hash_mapper 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -81,7 +81,7 @@ You can use HashMapper in your own little hash-like objects:
81
81
 
82
82
  ==== Coercing values
83
83
 
84
- You want to make sure an incoming value get converted to a certain type, so
84
+ You want to make sure an incoming value gets converted to a certain type, so
85
85
 
86
86
  {'one' => '1', 'two' => '2'} gets translated to {:one => 1, :two => 2}
87
87
 
@@ -168,9 +168,6 @@ Now ProjectMapper will delegate parsing of :author_names to UserMapper
168
168
 
169
169
  ProjectMapper.normalize( input ) # => output
170
170
 
171
- * Note the ampersand in &UserMapper. This is important if you are passing custom classes instead of procs.
172
- * If you want to implement your own filter class just define to_proc in it.
173
-
174
171
  Let's say you have a CompanyMapper which maps a hash with an array of employees, and you want to reuse UserMapper to map each employee. You could:
175
172
 
176
173
  class CompanyMapper
@@ -226,13 +223,9 @@ Note also that 'output' is correct at the time of the filter, i.e. before_normal
226
223
 
227
224
  == INSTALL:
228
225
 
229
- # If you haven't done this already:
230
-
231
- gem sources -a http://gems.github.com
232
-
233
226
  # Now install
234
227
 
235
- sudo gem install ismasan-hash_mapper
228
+ sudo gem install hash_mapper
236
229
 
237
230
  == Credits:
238
231
 
@@ -240,6 +233,7 @@ Note also that 'output' is correct at the time of the filter, i.e. before_normal
240
233
  * Mark Evans (Contributor - http://github.com/markevans)
241
234
  * Jdeveloper (Contributor - http://github.com/jdeveloper)
242
235
  * nightscape (Contributor - http://github.com/nightscape)
236
+ * radamanthus (Contributor - http://github.com/radamanthus)
243
237
 
244
238
  == LICENSE:
245
239
 
data/Rakefile CHANGED
@@ -15,6 +15,7 @@ begin
15
15
  gemspec.description = "Tiny module that allows you to easily adapt from one hash structure to another with a simple declarative DSL."
16
16
  gemspec.email = "ismaelct@gmail.com"
17
17
  gemspec.homepage = "http://github.com/ismasan/hash_mapper"
18
+ gemspec.add_dependency('active_support', '>= 3.0.0.beta')
18
19
  gemspec.authors = ["Ismael Celis"]
19
20
  end
20
21
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
data/hash_mapper.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hash_mapper}
8
- s.version = "0.0.9"
8
+ s.version = "0.0.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ismael Celis"]
12
- s.date = %q{2009-10-29}
12
+ s.date = %q{2010-09-21}
13
13
  s.description = %q{Tiny module that allows you to easily adapt from one hash structure to another with a simple declarative DSL.}
14
14
  s.email = %q{ismaelct@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.homepage = %q{http://github.com/ismasan/hash_mapper}
36
36
  s.rdoc_options = ["--charset=UTF-8"]
37
37
  s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.3.5}
38
+ s.rubygems_version = %q{1.3.7}
39
39
  s.summary = %q{Maps values from hashes with different structures and/or key names. Ideal for normalizing arbitrary data to be consumed by your applications, or to prepare your data for different display formats (ie. json)}
40
40
  s.test_files = [
41
41
  "spec/hash_mapper_spec.rb",
@@ -46,9 +46,13 @@ Gem::Specification.new do |s|
46
46
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
47
  s.specification_version = 3
48
48
 
49
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<active_support>, [">= 3.0.0.beta"])
50
51
  else
52
+ s.add_dependency(%q<active_support>, [">= 3.0.0.beta"])
51
53
  end
52
54
  else
55
+ s.add_dependency(%q<active_support>, [">= 3.0.0.beta"])
53
56
  end
54
57
  end
58
+
data/lib/hash_mapper.rb CHANGED
@@ -4,11 +4,8 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  def require_active_support
5
5
  require 'active_support/core_ext/array/extract_options'
6
6
  require 'active_support/core_ext/hash/indifferent_access'
7
- require 'active_support/core_ext/duplicable'
8
- Array.send(:include, ActiveSupport::CoreExtensions::Array::ExtractOptions)
9
- Hash.send(:include, ActiveSupport::CoreExtensions::Hash::IndifferentAccess)
7
+ require 'active_support/core_ext/object/duplicable'
10
8
  require 'active_support/core_ext/class/inheritable_attributes'
11
-
12
9
  end
13
10
 
14
11
  begin
@@ -123,21 +120,19 @@ module HashMapper
123
120
 
124
121
  def process_into(output, input, meth = :normalize)
125
122
  path_1, path_2 = (meth == :normalize ? [path_from, path_to] : [path_to, path_from])
126
- catch :no_value do
127
- value = get_value_from_input(output, input, path_1, meth)
128
- add_value_to_hash!(output, path_2, value)
129
- end
123
+ value = get_value_from_input(output, input, path_1, meth)
124
+ add_value_to_hash!(output, path_2, value) unless value == :hash_mapper_no_value
130
125
  end
131
126
  protected
132
127
 
133
128
  def get_value_from_input(output, input, path, meth)
134
129
  value = path.inject(input) do |h,e|
135
- if h.respond_to?(:with_indifferent_access)# this does it, but uses ActiveSupport
136
- v = h.with_indifferent_access[e]
130
+ if h.is_a?(Hash)
131
+ v = [h[e.to_sym], h[e.to_s]].compact.first
137
132
  else
138
133
  v = h[e]
139
134
  end
140
- throw :no_value if v.nil?#.has_key?(e)
135
+ return :hash_mapper_no_value if v.nil?
141
136
  v
142
137
  end
143
138
  delegated_mapper ? delegate_to_nested_mapper(value, meth) : value
@@ -149,7 +144,7 @@ module HashMapper
149
144
  when Array
150
145
  value.map {|h| delegated_mapper.send(meth, h)}
151
146
  when nil
152
- throw :no_value
147
+ return :hash_mapper_no_value
153
148
  else
154
149
  delegated_mapper.send(meth, value)
155
150
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ hash: 11
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 10
10
+ version: 0.0.10
5
11
  platform: ruby
6
12
  authors:
7
13
  - Ismael Celis
@@ -9,10 +15,26 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-29 00:00:00 +00:00
18
+ date: 2010-09-21 00:00:00 +01:00
13
19
  default_executable:
14
- dependencies: []
15
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: active_support
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 31098225
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ - beta
35
+ version: 3.0.0.beta
36
+ type: :runtime
37
+ version_requirements: *id001
16
38
  description: Tiny module that allows you to easily adapt from one hash structure to another with a simple declarative DSL.
17
39
  email: ismaelct@gmail.com
18
40
  executables: []
@@ -47,21 +69,27 @@ rdoc_options:
47
69
  require_paths:
48
70
  - lib
49
71
  required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
50
73
  requirements:
51
74
  - - ">="
52
75
  - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
53
79
  version: "0"
54
- version:
55
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
56
82
  requirements:
57
83
  - - ">="
58
84
  - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
59
88
  version: "0"
60
- version:
61
89
  requirements: []
62
90
 
63
91
  rubyforge_project:
64
- rubygems_version: 1.3.5
92
+ rubygems_version: 1.3.7
65
93
  signing_key:
66
94
  specification_version: 3
67
95
  summary: Maps values from hashes with different structures and/or key names. Ideal for normalizing arbitrary data to be consumed by your applications, or to prepare your data for different display formats (ie. json)