Module: Fabrik::Trait

Extended by:
Forwardable
Includes:
Composer
Defined in:
lib/fabrik/trait.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Composer

#compose

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

#dictionaryObject



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

#ownObject



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