Class: Filament::Platform
- Inherits:
-
Object
- Object
- Filament::Platform
- Defined in:
- lib/filament/platform.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .create(name, attributes) ⇒ Object
- .find(h) ⇒ Object
- .import(data) ⇒ Object
- .property(*attrs) ⇒ Object
- .property_list(*attrs) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
66 67 68 |
# File 'lib/filament/platform.rb', line 66 def name @name end |
Class Method Details
.create(name, attributes) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/filament/platform.rb', line 45 def self.create(name, attributes) name = name.to_sym prototypes = attributes.delete(:inherit) || [] prototypes = prototypes.to_a platform = new(name, prototypes, attributes) @@platforms ||= {} @@platforms[name] = platform end |
.find(h) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/filament/platform.rb', line 56 def self.find(h) name = h[:name].to_sym @@platforms ||= {} return @@platforms[name] end |
.import(data) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/filament/platform.rb', line 32 def self.import(data) platforms = YAML.load(data) platforms.each do |name, map| attributes = {} map.each do |key, value| attributes[key.to_sym] = value end create(name, attributes) end end |
.property(*attrs) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/filament/platform.rb', line 5 def self.property(*attrs) attrs.each do |a| attr_writer(a) define_method(a) do value = @attributes[a] return value unless value.nil? prototypes.each do |p| value = p.send(a) break if value.nil? end return value end end end |
.property_list(*attrs) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/filament/platform.rb', line 20 def self.property_list(*attrs) attrs.each do |a| attr_writer(a) define_method(a) do value = @attributes[a] || [] value = value.to_a prototypes.each {|p| value += p.send(a)} return value end end end |