Class: Goku::ElementFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/goku/element_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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_namesObject



26
27
28
# File 'lib/goku/element_factory.rb', line 26

def ancestor_names
  @ancestor_names ||= @path.directories.drop(1)
end

#ancestorsObject



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_classObject



10
11
12
# File 'lib/goku/element_factory.rb', line 10

def create_class
  nested(Goku::Elements::Class.new(path.filename))
end

#create_moduleObject



14
15
16
# File 'lib/goku/element_factory.rb', line 14

def create_module
  nested(Goku::Elements::Module.new(path.filename))
end

#create_specObject



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