Class: Taketo::Constructs::BaseConstruct

Inherits:
Object
  • Object
show all
Includes:
AssociatedNodes
Defined in:
lib/taketo/constructs/base_construct.rb

Direct Known Subclasses

Command, Config, Environment, Group, Project, Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AssociatedNodes

included

Constructor Details

#initialize(name) ⇒ BaseConstruct

Returns a new instance of BaseConstruct.



14
15
16
17
18
19
# File 'lib/taketo/constructs/base_construct.rb', line 14

def initialize(name)
  super
  @name = name
  @default_server_config = proc {}
  @parent = NullConstruct
end

Instance Attribute Details

#default_server_configObject



46
47
48
49
50
# File 'lib/taketo/constructs/base_construct.rb', line 46

def default_server_config
  parent_default_server_config = parent.default_server_config
  own_default_server_config = @default_server_config
  proc { instance_eval(&parent_default_server_config); instance_eval(&own_default_server_config)}
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/taketo/constructs/base_construct.rb', line 11

def name
  @name
end

#parentObject

Returns the value of attribute parent.



10
11
12
# File 'lib/taketo/constructs/base_construct.rb', line 10

def parent
  @parent
end

Instance Method Details

#node_typeObject



21
22
23
24
# File 'lib/taketo/constructs/base_construct.rb', line 21

def node_type
  demodulized = self.class.name.gsub(/.*::/, '')
  demodulized.gsub(/([a-z])([A-Z])/, '\\1_\\2').downcase.to_sym
end

#parentsObject



32
33
34
35
36
37
38
39
40
# File 'lib/taketo/constructs/base_construct.rb', line 32

def parents
  result = []
  p = parent
  while p != NullConstruct
    result << p
    p = p.parent
  end
  result
end

#pathObject



42
43
44
# File 'lib/taketo/constructs/base_construct.rb', line 42

def path
  parents.reverse_each.map(&:name).concat([self.name]).reject(&:nil?).join(":")
end

#qualified_nameObject



52
53
54
# File 'lib/taketo/constructs/base_construct.rb', line 52

def qualified_name
  "#{node_type} #{self.name}"
end