class Protopack::PackageItem
Attributes
attributes[RW]
default_locale[RW]
description[RW]
id[RW]
locale[RW]
ordinal[RW]
protopack_filename[RW]
resources[RW]
type[RW]
Public Class Methods
load(filename)
click to toggle source
# 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
Public Instance Methods
apply!()
click to toggle source
# 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()
click to toggle source
# File lib/protopack/package_item.rb, line 28 def existence target_class.existence attributes end
load_resources(hsh, d = File.dirname(protopack_filename))
click to toggle source
# 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)
click to toggle source
# 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?()
click to toggle source
# File lib/protopack/package_item.rb, line 24 def missing? existence.empty? end
name()
click to toggle source
# File lib/protopack/package_item.rb, line 12 def name ; attributes[:name] || attributes["name"] ; end
target_class()
click to toggle source
# File lib/protopack/package_item.rb, line 20 def target_class lookup_class Kernel, type.split("::") end