Class: Goku::ElementFactory
- Inherits:
-
Object
- Object
- Goku::ElementFactory
- Defined in:
- lib/goku/element_factory.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #ancestor_names ⇒ Object
- #ancestors ⇒ Object
- #create_class ⇒ Object
- #create_module ⇒ Object
- #create_spec ⇒ Object
-
#initialize(path) ⇒ ElementFactory
constructor
A new instance of ElementFactory.
- #nested(element) ⇒ Object
Constructor Details
#initialize(path) ⇒ ElementFactory
Returns a new instance of ElementFactory.
6 7 8 |
# File 'lib/goku/element_factory.rb', line 6 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/goku/element_factory.rb', line 4 def path @path end |
Instance Method Details
#ancestor_names ⇒ Object
26 27 28 |
# File 'lib/goku/element_factory.rb', line 26 def ancestor_names @ancestor_names ||= @path.directories.drop(1) end |
#ancestors ⇒ Object
22 23 24 |
# File 'lib/goku/element_factory.rb', line 22 def ancestors @ancestors ||= ancestor_names.map { |m| Goku::Elements::Module.new(m) } end |
#create_class ⇒ Object
10 11 12 |
# File 'lib/goku/element_factory.rb', line 10 def create_class nested(Goku::Elements::Class.new(path.filename)) end |
#create_module ⇒ Object
14 15 16 |
# File 'lib/goku/element_factory.rb', line 14 def create_module nested(Goku::Elements::Module.new(path.filename)) end |
#create_spec ⇒ Object
18 19 20 |
# File 'lib/goku/element_factory.rb', line 18 def create_spec Goku::Elements::Spec.new(path.filename, ancestor_names) end |
#nested(element) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/goku/element_factory.rb', line 30 def nested(element) ancestors.each_cons(2) { |parent, sub| parent.add(sub) } ancestors.last.add(element) ancestors.first end |