Module: Flatter::Mapper::Traits::ClassMethods

Defined in:
lib/flatter/mapper/traits.rb

Instance Method Summary collapse

Instance Method Details

#mount(&block) ⇒ Object



26
27
28
# File 'lib/flatter/mapper/traits.rb', line 26

def mount(*, &block)
  super.tap{ |f| f.extension = block }
end

#trait(trait_name, label: name, includes: nil, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/flatter/mapper/traits.rb', line 30

def trait(trait_name, label: name, includes: nil, &block)
  trait_name   = "#{trait_name}_trait"
  mapper_class = Class.new(Flatter::Mapper)
  mapper_class.label = label
  mapper_class.class_eval(&block) if block.present?

  if self.name.present?
    mapper_class_name = trait_name.camelize
    const_set(mapper_class_name, mapper_class)
  end

  mount trait_name, mapper_class: mapper_class, trait: true, includes: includes
end