Module: FlatMap::OpenMapper::Traits::ClassMethods
- Defined in:
- lib/flat_map/open_mapper/traits.rb
Overview
Traits class macros
Instance Method Summary collapse
-
#trait(name, &block) ⇒ Object
Define a trait for a mapper class.
Instance Method Details
#trait(name, &block) ⇒ Object
Define a trait for a mapper class. In implementation terms, a trait is nothing more than a mounted mapper, owned by a host mapper. It shares all mappings with it. The block is passed as a body of the anonymous mapper class.
18 19 20 21 22 23 24 |
# File 'lib/flat_map/open_mapper/traits.rb', line 18 def trait(name, &block) base_class = self < FlatMap::Mapper ? FlatMap::Mapper : FlatMap::OpenMapper mapper_class = Class.new(base_class, &block) mapper_class_name = "#{ancestors.first.name}#{name.to_s.camelize}Trait" mapper_class.singleton_class.send(:define_method, :name){ mapper_class_name } mount mapper_class, :trait_name => name end |