Class: Protopack::PackageItem
- Inherits:
-
Aduki::Initializable
- Object
- Aduki::Initializable
- Protopack::PackageItem
- Defined in:
- lib/protopack/package_item.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#default_locale ⇒ Object
Returns the value of attribute default_locale.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#ordinal ⇒ Object
Returns the value of attribute ordinal.
-
#protopack_filename ⇒ Object
Returns the value of attribute protopack_filename.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #apply! ⇒ Object
- #existence ⇒ Object
- #load_resources(hsh, d = File.dirname(protopack_filename)) ⇒ Object
- #lookup_class(base, list) ⇒ Object
- #missing? ⇒ Boolean
- #name ⇒ Object
- #target_class ⇒ Object
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/protopack/package_item.rb', line 8 def attributes @attributes end |
#default_locale ⇒ Object
Returns the value of attribute default_locale.
5 6 7 |
# File 'lib/protopack/package_item.rb', line 5 def default_locale @default_locale end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/protopack/package_item.rb', line 3 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/protopack/package_item.rb', line 2 def id @id end |
#locale ⇒ Object
Returns the value of attribute locale.
4 5 6 |
# File 'lib/protopack/package_item.rb', line 4 def locale @locale end |
#ordinal ⇒ Object
Returns the value of attribute ordinal.
7 8 9 |
# File 'lib/protopack/package_item.rb', line 7 def ordinal @ordinal end |
#protopack_filename ⇒ Object
Returns the value of attribute protopack_filename.
10 11 12 |
# File 'lib/protopack/package_item.rb', line 10 def protopack_filename @protopack_filename end |
#resources ⇒ Object
Returns the value of attribute resources.
9 10 11 |
# File 'lib/protopack/package_item.rb', line 9 def resources @resources end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/protopack/package_item.rb', line 6 def type @type end |
Class Method Details
.load(filename) ⇒ Object
48 49 50 51 52 |
# File 'lib/protopack/package_item.rb', line 48 def self.load filename Protopack::PackageItem.new(YAML.load(File.read(filename)).merge(protopack_filename: filename)) rescue raise "error reading from file #{filename}" end |
Instance Method Details
#apply! ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/protopack/package_item.rb', line 39 def apply! factory = existence if factory.empty? factory.create! load_resources(attributes.to_hash) else factory.first.update_attributes attributes.to_hash end end |
#existence ⇒ Object
28 29 30 |
# File 'lib/protopack/package_item.rb', line 28 def existence target_class.existence attributes end |
#load_resources(hsh, d = File.dirname(protopack_filename)) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/protopack/package_item.rb', line 32 def load_resources hsh, d = File.dirname(protopack_filename) (resources || {}).inject(hsh) { |hsh, (k, v)| hsh[k] = File.read(File.join d, v) hsh } end |
#lookup_class(base, list) ⇒ Object
14 15 16 17 18 |
# File 'lib/protopack/package_item.rb', line 14 def lookup_class base, list base = base.const_get list.shift return base if list.empty? lookup_class base, list end |
#missing? ⇒ Boolean
24 25 26 |
# File 'lib/protopack/package_item.rb', line 24 def missing? existence.empty? end |
#name ⇒ Object
12 |
# File 'lib/protopack/package_item.rb', line 12 def name ; attributes[:name] || attributes["name"] ; end |
#target_class ⇒ Object
20 21 22 |
# File 'lib/protopack/package_item.rb', line 20 def target_class lookup_class Kernel, type.split("::") end |