Module: HashMapper

Defined in:
lib/hash_mapper.rb

Defined Under Namespace

Classes: Map, PathMap

Constant Summary collapse

VERSION =
'0.0.8'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

we need this for inheritable mappers, which is annoying because it needs ActiveSupport, kinda overkill.



47
48
49
50
51
52
# File 'lib/hash_mapper.rb', line 47

def self.extended(base)
  base.class_eval do
    write_inheritable_attribute :maps, []
    class_inheritable_accessor :maps
  end
end

Instance Method Details

#after_denormalize(&blk) ⇒ Object



91
92
93
# File 'lib/hash_mapper.rb', line 91

def after_denormalize(&blk)
  @after_denormalize = blk
end

#after_normalize(&blk) ⇒ Object



87
88
89
# File 'lib/hash_mapper.rb', line 87

def after_normalize(&blk)
  @after_normalize = blk
end

#before_denormalize(&blk) ⇒ Object



83
84
85
# File 'lib/hash_mapper.rb', line 83

def before_denormalize(&blk)
  @before_denormalize = blk
end

#before_normalize(&blk) ⇒ Object



79
80
81
# File 'lib/hash_mapper.rb', line 79

def before_normalize(&blk)
  @before_normalize = blk
end

#denormalize(a_hash) ⇒ Object



75
76
77
# File 'lib/hash_mapper.rb', line 75

def denormalize(a_hash)
  perform_hash_mapping a_hash, :denormalize
end

#from(path, &filter) ⇒ Object Also known as: to



59
60
61
62
63
# File 'lib/hash_mapper.rb', line 59

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, using = nil, &filter) ⇒ Object



54
55
56
57
# File 'lib/hash_mapper.rb', line 54

def map(from, to, using=nil, &filter)
  self.maps << Map.new(from, to, using)
  to.filter = filter if block_given? # Useful if just one block given
end

#normalize(a_hash) ⇒ Object



71
72
73
# File 'lib/hash_mapper.rb', line 71

def normalize(a_hash)
  perform_hash_mapping a_hash, :normalize
end

#using(mapper_class) ⇒ Object



67
68
69
# File 'lib/hash_mapper.rb', line 67

def using(mapper_class)
  mapper_class
end