Class: Train::Platforms::Platform
- Inherits:
-
Object
- Object
- Train::Platforms::Platform
- Includes:
- Common
- Defined in:
- lib/train/platforms/platform.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#families ⇒ Object
Returns the value of attribute families.
-
#family_hierarchy ⇒ Object
Returns the value of attribute family_hierarchy.
-
#platform ⇒ Object
Returns the value of attribute platform.
Instance Method Summary collapse
-
#[](name) ⇒ Object
This is for backwards compatibility with the current inspec os resource.
-
#add_platform_methods ⇒ Object
Add generic family? and platform methods to an existing platform.
- #clean_name(force: false) ⇒ Object
- #direct_families ⇒ Object
- #family ⇒ Object
- #find_family_hierarchy(platform = self) ⇒ Object
-
#initialize(name, condition = {}) ⇒ Platform
constructor
A new instance of Platform.
- #name ⇒ Object
- #title(title = nil) ⇒ Object
- #to_hash ⇒ Object
- #uuid ⇒ Object
Methods included from Common
#detect, #in_family, #inspect, #to_s
Constructor Details
#initialize(name, condition = {}) ⇒ Platform
Returns a new instance of Platform.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/train/platforms/platform.rb', line 6 def initialize(name, condition = {}) @name = name @condition = condition @families = {} @family_hierarchy = [] @platform = {} @detect = nil @title = name.to_s.capitalize # add itself to the platform list Train::Platforms.list[name] = self end |
Instance Attribute Details
#backend ⇒ Object
Returns the value of attribute backend.
4 5 6 |
# File 'lib/train/platforms/platform.rb', line 4 def backend @backend end |
#condition ⇒ Object
Returns the value of attribute condition.
4 5 6 |
# File 'lib/train/platforms/platform.rb', line 4 def condition @condition end |
#families ⇒ Object
Returns the value of attribute families.
4 5 6 |
# File 'lib/train/platforms/platform.rb', line 4 def families @families end |
#family_hierarchy ⇒ Object
Returns the value of attribute family_hierarchy.
4 5 6 |
# File 'lib/train/platforms/platform.rb', line 4 def family_hierarchy @family_hierarchy end |
#platform ⇒ Object
Returns the value of attribute platform.
4 5 6 |
# File 'lib/train/platforms/platform.rb', line 4 def platform @platform end |
Instance Method Details
#[](name) ⇒ Object
This is for backwards compatibility with the current inspec os resource.
50 51 52 53 54 55 56 |
# File 'lib/train/platforms/platform.rb', line 50 def[](name) if respond_to?(name) send(name) else "unknown" end end |
#add_platform_methods ⇒ Object
Add generic family? and platform methods to an existing platform
This is done later to add any custom families/properties that were created
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/train/platforms/platform.rb', line 73 def add_platform_methods # Redo clean name if there is a detect override clean_name(force: true) unless @platform[:name].nil? # Add in family methods family_list = Train::Platforms.families family_list.each_value do |k| name = "#{k.name}?" next if respond_to?(name) define_singleton_method(name) do family_hierarchy.include?(k.name) end end # Helper methods for direct platform info @platform.each_key do |m| next if respond_to?(m) define_singleton_method(m) do @platform[m] end end # Create method for name if its not already true m = name + "?" return if respond_to?(m) define_singleton_method(m) do true end end |
#clean_name(force: false) ⇒ Object
39 40 41 42 |
# File 'lib/train/platforms/platform.rb', line 39 def clean_name(force: false) @cleaned_name = nil if force @cleaned_name ||= (@platform[:name] || @name).downcase.tr(" ", "_") end |
#direct_families ⇒ Object
19 20 21 |
# File 'lib/train/platforms/platform.rb', line 19 def direct_families @families.collect { |k, _v| k.name } end |
#family ⇒ Object
29 30 31 |
# File 'lib/train/platforms/platform.rb', line 29 def family @platform[:family] || @family_hierarchy[0] end |
#find_family_hierarchy(platform = self) ⇒ Object
23 24 25 26 27 |
# File 'lib/train/platforms/platform.rb', line 23 def find_family_hierarchy(platform = self) families = platform.families.map { |k, v| [k.name, find_family_hierarchy(k)] } @family_hierarchy = families.flatten end |
#name ⇒ Object
33 34 35 36 37 |
# File 'lib/train/platforms/platform.rb', line 33 def name # Override here incase a updated name was set # during the detect logic clean_name end |
#title(title = nil) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/train/platforms/platform.rb', line 58 def title(title = nil) return @title if title.nil? @title = title self end |
#to_hash ⇒ Object
65 66 67 |
# File 'lib/train/platforms/platform.rb', line 65 def to_hash @platform end |