Class: Oschii::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/oschii/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, config) ⇒ Component

Returns a new instance of Component.



3
4
5
6
# File 'lib/oschii/component.rb', line 3

def initialize(type, config)
  @type = type
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/oschii/component.rb', line 8

def config
  @config
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/oschii/component.rb', line 8

def type
  @type
end

Instance Method Details

#array_nameObject



14
15
16
# File 'lib/oschii/component.rb', line 14

def array_name
  @array_name ||= "#{type.capitalize}s"
end

#inspectObject



45
46
47
# File 'lib/oschii/component.rb', line 45

def inspect
  "#<#{self.class.name} '#{reference}'>"
end

#nameObject



10
11
12
# File 'lib/oschii/component.rb', line 10

def name
  @name ||= config['name']
end

#referenceObject



18
19
20
# File 'lib/oschii/component.rb', line 18

def reference
  "#{type}:#{name}"
end

#routesObject



22
23
24
# File 'lib/oschii/component.rb', line 22

def routes
  @routes ||= config['routes'] || config['Routes'] || config['subs'] || config['Subs'] || []
end

#targetsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/oschii/component.rb', line 26

def targets
  return @targets if @targets

  @targets = config['targets'] || config['target'] || config['~'] || []
  @targets = [@targets] if @targets.is_a?(String)

  routes.each do |route|
    target_refs = route['targets'] || route['target'] || route['~'] || []
    target_refs = [target_refs] if target_refs.is_a?(String)
    @targets += target_refs
  end
  
  @targets = @targets.map { |ref| ref.split('/').first }.uniq
end

#to_sObject



41
42
43
# File 'lib/oschii/component.rb', line 41

def to_s
  inspect
end