Class: Oschii::Component
- Inherits:
-
Object
- Object
- Oschii::Component
- Defined in:
- lib/oschii/component.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #array_name ⇒ Object
-
#initialize(type, config) ⇒ Component
constructor
A new instance of Component.
- #inspect ⇒ Object
- #name ⇒ Object
- #reference ⇒ Object
- #routes ⇒ Object
- #targets ⇒ Object
- #to_s ⇒ Object
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/oschii/component.rb', line 8 def config @config end |
#type ⇒ Object (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_name ⇒ Object
14 15 16 |
# File 'lib/oschii/component.rb', line 14 def array_name @array_name ||= "#{type.capitalize}s" end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/oschii/component.rb', line 45 def inspect "#<#{self.class.name} '#{reference}'>" end |
#name ⇒ Object
10 11 12 |
# File 'lib/oschii/component.rb', line 10 def name @name ||= config['name'] end |
#reference ⇒ Object
18 19 20 |
# File 'lib/oschii/component.rb', line 18 def reference "#{type}:#{name}" end |
#routes ⇒ Object
22 23 24 |
# File 'lib/oschii/component.rb', line 22 def routes @routes ||= config['routes'] || config['Routes'] || config['subs'] || config['Subs'] || [] end |
#targets ⇒ Object
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_s ⇒ Object
41 42 43 |
# File 'lib/oschii/component.rb', line 41 def to_s inspect end |