Module: Intermodal::DSL::Mapping

Extended by:
ActiveSupport::Concern
Included in:
API
Defined in:
lib/intermodal/dsl/mapping.rb

Instance Method Summary collapse

Instance Method Details

#acceptance_for(resource, options = {}, &customizations) ⇒ Object



35
36
37
# File 'lib/intermodal/dsl/mapping.rb', line 35

def acceptance_for(resource, options = {}, &customizations)
  acceptors[resource.to_sym] = mapping_for(resource, Intermodal::Mapping::Acceptor, &customizations)
end

#acceptor_for(model) ⇒ Object



57
58
59
# File 'lib/intermodal/dsl/mapping.rb', line 57

def acceptor_for(model)
  acceptors[model_name(model)]
end

#acceptorsObject



53
54
55
# File 'lib/intermodal/dsl/mapping.rb', line 53

def acceptors
  self._acceptors ||= {}
end

#accepts_resource(resource, options = {}) ⇒ Object



73
74
75
# File 'lib/intermodal/dsl/mapping.rb', line 73

def accepts_resource(resource, options = {})
  accepts[resource_name(resource)].call(resource, options)
end

#load_presentations!Object

Setup



40
41
42
# File 'lib/intermodal/dsl/mapping.rb', line 40

def load_presentations!
  _presentation_description.call
end

#map_data(&blk) ⇒ Object

DSL



19
20
21
# File 'lib/intermodal/dsl/mapping.rb', line 19

def map_data(&blk)
  self._presentation_description = blk
end

#mapping_for(resource, mapper, &customizations) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/intermodal/dsl/mapping.rb', line 23

def mapping_for(resource, mapper, &customizations)
  Class.new(mapper).tap do |template|
    template.api = self
    template._property_mappings = {}
    template.instance_eval(&customizations)
  end
end

#model_name(model) ⇒ Object



61
62
63
# File 'lib/intermodal/dsl/mapping.rb', line 61

def model_name(model)
  model.name.underscore.to_sym
end

#presentation_for(resource, options = {}, &customizations) ⇒ Object



31
32
33
# File 'lib/intermodal/dsl/mapping.rb', line 31

def presentation_for(resource, options = {},  &customizations)
  presenters[resource.to_sym] = mapping_for(resource, Intermodal::Mapping::Presenter, &customizations)
end

#presenter_for(model) ⇒ Object



49
50
51
# File 'lib/intermodal/dsl/mapping.rb', line 49

def presenter_for(model)
  presenters[model_name(model)]
end

#presentersObject

Accessors



45
46
47
# File 'lib/intermodal/dsl/mapping.rb', line 45

def presenters
  self._presenters ||= {}
end

#presents_resource(resource, options = {}) ⇒ Object



69
70
71
# File 'lib/intermodal/dsl/mapping.rb', line 69

def presents_resource(resource, options = {})
  presenters[resource_name(resource)].call(resource, options)
end

#resource_name(resource) ⇒ Object



65
66
67
# File 'lib/intermodal/dsl/mapping.rb', line 65

def resource_name(resource)
  model_name(resource.class)
end