Module: HashMapper

Defined in:
lib/hash_mapper.rb

Defined Under Namespace

Classes: Map, PathMap

Constant Summary collapse

VERSION =
'0.0.6'

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.



37
38
39
40
41
42
# File 'lib/hash_mapper.rb', line 37

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



81
82
83
# File 'lib/hash_mapper.rb', line 81

def after_denormalize(&blk)
  @after_denormalize = blk
end

#after_normalize(&blk) ⇒ Object



77
78
79
# File 'lib/hash_mapper.rb', line 77

def after_normalize(&blk)
  @after_normalize = blk
end

#before_denormalize(&blk) ⇒ Object



73
74
75
# File 'lib/hash_mapper.rb', line 73

def before_denormalize(&blk)
  @before_denormalize = blk
end

#before_normalize(&blk) ⇒ Object



69
70
71
# File 'lib/hash_mapper.rb', line 69

def before_normalize(&blk)
  @before_normalize = blk
end

#denormalize(a_hash) ⇒ Object



65
66
67
# File 'lib/hash_mapper.rb', line 65

def denormalize(a_hash)
  perform_hash_mapping a_hash, :denormalize
end

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



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

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



44
45
46
47
# File 'lib/hash_mapper.rb', line 44

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



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

def normalize(a_hash)
  perform_hash_mapping a_hash, :normalize
end

#using(mapper_class) ⇒ Object



57
58
59
# File 'lib/hash_mapper.rb', line 57

def using(mapper_class)
  mapper_class
end