Module: Fabrik::Trait
Class Method Summary collapse
Instance Method Summary collapse
- #dictionary ⇒ Object
- #methods(opts = {}) ⇒ Object (also: #[])
- #own ⇒ Object
- #provides(&own_definition) ⇒ Object
- #provides_from(mod, *names) ⇒ Object
Methods included from Composer
Class Method Details
.build(*args, &blk) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/fabrik/trait.rb', line 12 def self.build(*args, &blk) Class.new do extend Trait compose(*args) if args.count > 0 provides(&blk) if blk end end |
Instance Method Details
#dictionary ⇒ Object
40 41 42 |
# File 'lib/fabrik/trait.rb', line 40 def dictionary @dictionary ||= Dictionary.new end |
#methods(opts = {}) ⇒ Object Also known as: []
20 21 22 23 |
# File 'lib/fabrik/trait.rb', line 20 def methods(opts = {}) provides_from(own, *own.instance_methods) dictionary.method_map(opts) end |
#own ⇒ Object
36 37 38 |
# File 'lib/fabrik/trait.rb', line 36 def own @own ||= Module.new end |
#provides(&own_definition) ⇒ Object
26 27 28 |
# File 'lib/fabrik/trait.rb', line 26 def provides(&own_definition) own.module_eval(&own_definition) end |
#provides_from(mod, *names) ⇒ Object
30 31 32 33 34 |
# File 'lib/fabrik/trait.rb', line 30 def provides_from(mod, *names) names.each do |name| dictionary.add([mod, name]) end end |