Module: HashMapper
- Defined in:
- lib/hash_mapper.rb,
lib/hash_mapper/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
Instance Method Summary collapse
- #after_denormalize(&blk) ⇒ Object
- #after_normalize(&blk) ⇒ Object
- #before_denormalize(&blk) ⇒ Object
- #before_normalize(&blk) ⇒ Object
- #denormalize(a_hash) ⇒ Object
- #from(path, &filter) ⇒ Object (also: #to)
- #map(from, to, options = {}, &filter) ⇒ Object
- #normalize(a_hash) ⇒ Object
- #using(mapper_class) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/hash_mapper.rb', line 43 def self.extended(base) base.class_eval do class_attribute :maps self.maps = [] end end |
Instance Method Details
#after_denormalize(&blk) ⇒ Object
89 90 91 |
# File 'lib/hash_mapper.rb', line 89 def after_denormalize(&blk) @after_denormalize = blk end |
#after_normalize(&blk) ⇒ Object
85 86 87 |
# File 'lib/hash_mapper.rb', line 85 def after_normalize(&blk) @after_normalize = blk end |
#before_denormalize(&blk) ⇒ Object
81 82 83 |
# File 'lib/hash_mapper.rb', line 81 def before_denormalize(&blk) @before_denormalize = blk end |
#before_normalize(&blk) ⇒ Object
77 78 79 |
# File 'lib/hash_mapper.rb', line 77 def before_normalize(&blk) @before_normalize = blk end |
#denormalize(a_hash) ⇒ Object
73 74 75 |
# File 'lib/hash_mapper.rb', line 73 def denormalize(a_hash) perform_hash_mapping a_hash, :denormalize end |
#from(path, &filter) ⇒ Object Also known as: to
56 57 58 59 60 |
# File 'lib/hash_mapper.rb', line 56 def from(path, &filter) path_map = PathMap.new(path) path_map.filter = filter if block_given? # Useful if two blocks given path_map end |
#map(from, to, options = {}, &filter) ⇒ Object
50 51 52 53 54 |
# File 'lib/hash_mapper.rb', line 50 def map(from, to, ={}, &filter) self.maps = self.maps.dup self.maps << Map.new(from, to, ) to.filter = filter if block_given? # Useful if just one block given end |
#normalize(a_hash) ⇒ Object
69 70 71 |
# File 'lib/hash_mapper.rb', line 69 def normalize(a_hash) perform_hash_mapping a_hash, :normalize end |
#using(mapper_class) ⇒ Object
64 65 66 67 |
# File 'lib/hash_mapper.rb', line 64 def using(mapper_class) warn "[DEPRECATION] `using` is deprecated, instead of `using(#{mapper_class.name})` you should specify `{ using: #{mapper_class.name} }`" { using: mapper_class } end |