From e67892b3565182b39e90c70669f647e11f1585ba Mon Sep 17 00:00:00 2001 From: Leif Gensert Date: Mon, 13 Jan 2014 12:10:03 +0100 Subject: [PATCH 1/3] rename stubs in specs --- spec/lib/morfo_spec.rb | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/spec/lib/morfo_spec.rb b/spec/lib/morfo_spec.rb index e92854f..a90497c 100644 --- a/spec/lib/morfo_spec.rb +++ b/spec/lib/morfo_spec.rb @@ -33,10 +33,10 @@ describe '#morf' do context 'errors' do subject(:no_from) do - class NilMapper < Morfo::Base + class NilMorfer < Morfo::Base field :my_field, {} end - NilMapper + NilMorfer end it 'raises error for nil field' do expect{no_from.morf([])}.to raise_error(ArgumentError) @@ -45,10 +45,10 @@ class NilMapper < Morfo::Base context '1 to 1 conversion' do subject do - class TitleMapper < Morfo::Base + class TitleMorfer < Morfo::Base field :tv_show_title, from: :title end - TitleMapper + TitleMorfer end it 'maps title correctly' do @@ -65,10 +65,10 @@ class TitleMapper < Morfo::Base context '1 to 1 conversion with transformation' do subject do - class NumCastMapper < Morfo::Base + class NumCastMorfer < Morfo::Base field(:cast_num, from: :cast){|v,r| v.size} end - NumCastMapper + NumCastMorfer end it 'calls transformation correctly' do @@ -79,11 +79,11 @@ class NumCastMapper < Morfo::Base context '1 to many conversion' do subject do - class MutliTitleMapper < Morfo::Base + class MutliTitleMorfer < Morfo::Base field :title, from: :title field :also_title, from: :title end - MutliTitleMapper + MutliTitleMorfer end it 'maps title to multiple fields' do @@ -95,24 +95,24 @@ class MutliTitleMapper < Morfo::Base context 'nested conversion' do context 'nested source' do subject(:valid_path) do - class ImdbRatingMapper < Morfo::Base + class ImdbRatingMorfer < Morfo::Base field :rating, from: [:ratings, :imdb] end - ImdbRatingMapper + ImdbRatingMorfer end subject(:valid_path_with_transformation) do - class ImdbRatingMapper < Morfo::Base + class ImdbRatingMorfer < Morfo::Base field(:rating, from: [:ratings, :imdb]){|v| "Rating: #{v}"} end - ImdbRatingMapper + ImdbRatingMorfer end subject(:invalid_path) do - class InvalidImdbRatingMapper < Morfo::Base + class InvalidImdbRatingMorfer < Morfo::Base field :rating, from: [:very, :long, :path, :that, :might, :not, :exist] end - InvalidImdbRatingMapper + InvalidImdbRatingMorfer end it 'maps nested attributes' do @@ -133,11 +133,11 @@ class InvalidImdbRatingMapper < Morfo::Base context 'nested destination' do subject do - class WrapperMapper < Morfo::Base + class WrapperMorfer < Morfo::Base field([:tv_show, :title], from: :title) field([:tv_show, :channel], from: :channel){|v| "Channel: #{v}"} end - WrapperMapper + WrapperMorfer end it 'maps to nested destination' do @@ -156,10 +156,10 @@ class WrapperMapper < Morfo::Base context 'calculations' do subject do - class TitlePrefixMapper < Morfo::Base + class TitlePrefixMorfer < Morfo::Base field(:title_with_channel){|v,r| "#{r[:title]}, (#{r[:channel]})"} end - TitlePrefixMapper + TitlePrefixMorfer end it 'maps calculation correctly' do @@ -174,10 +174,10 @@ class TitlePrefixMapper < Morfo::Base context 'static values' do subject do - class StaticTitleMapper < Morfo::Base + class StaticTitleMorfer < Morfo::Base field(:new_title){ 'Static Title' } end - StaticTitleMapper + StaticTitleMorfer end it 'maps static value correctly' do From 5615783cca6d9fe59fa118344e7d4abcdf2f9dd9 Mon Sep 17 00:00:00 2001 From: Leif Gensert Date: Mon, 13 Jan 2014 12:42:55 +0100 Subject: [PATCH 2/3] change name in benchmarks --- benchmarks/data.rb | 8 ++++---- benchmarks/run.rb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/benchmarks/data.rb b/benchmarks/data.rb index 520be32..d55217e 100644 --- a/benchmarks/data.rb +++ b/benchmarks/data.rb @@ -44,19 +44,19 @@ def stringify_keys hash hash end - class SimpleMappingSymbol < Morfo::Base + class SimpleMorferSymbol < Morfo::Base BenchmarkData.row.keys.each do |field| field(:"#{field}_mapped", from: field) end end - class SimpleMappingString < Morfo::Base + class SimpleMorferString < Morfo::Base BenchmarkData.row_string_keys.keys.each do |field| field("#{field}_mapped", from: field) end end - class NestedMappingSymbol < Morfo::Base + class NestedMorferSymbol < Morfo::Base BenchmarkData.row_nested.each do |key, value| value.keys.each do |field| field(:"#{field}_mapped", from: [key, field]) @@ -64,7 +64,7 @@ class NestedMappingSymbol < Morfo::Base end end - class NestedMappingString < Morfo::Base + class NestedMorferString < Morfo::Base BenchmarkData.row_nested_string_keys.each do |key, value| value.keys.each do |field| field("#{field}_mapped", from: [key, field]) diff --git a/benchmarks/run.rb b/benchmarks/run.rb index 138f087..e0ea8e9 100644 --- a/benchmarks/run.rb +++ b/benchmarks/run.rb @@ -9,22 +9,22 @@ { label: 'Simple (strings)', row: BenchmarkData.row_string_keys, - morf_class: BenchmarkData::SimpleMappingString + morf_class: BenchmarkData::SimpleMorferString }, { label: 'Simple (symbols)', row: BenchmarkData.row, - morf_class: BenchmarkData::SimpleMappingSymbol + morf_class: BenchmarkData::SimpleMorferSymbol }, { label: 'Nested (strings)', row: BenchmarkData.row_nested_string_keys, - morf_class: BenchmarkData::NestedMappingString + morf_class: BenchmarkData::NestedMorferString }, { label: 'Nested (symbols)', row: BenchmarkData.row_nested, - morf_class: BenchmarkData::NestedMappingSymbol + morf_class: BenchmarkData::NestedMorferSymbol }, ] From dae690b3d5cc69abf12dfd74e91e1af6efeae6e9 Mon Sep 17 00:00:00 2001 From: Leif Gensert Date: Mon, 13 Jan 2014 12:43:25 +0100 Subject: [PATCH 3/3] remove map from error message --- lib/morfo.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/morfo.rb b/lib/morfo.rb index 538dbba..c6ac8f9 100644 --- a/lib/morfo.rb +++ b/lib/morfo.rb @@ -9,7 +9,7 @@ def self.field field_name, definition={}, &blk else raise( ArgumentError, - "No field to map from is specified for #{field_name.inspect}" + "No field to get value from is specified for #{field_name.inspect}" ) unless definition[:from] mapping_actions << Morfo::Actions::MapAction.new(definition[:from], field_name) end