Class: Protopack::Package
- Inherits:
-
Aduki::Initializable
- Object
- Aduki::Initializable
- Protopack::Package
- Defined in:
- lib/protopack/package.rb
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#description ⇒ Object
Returns the value of attribute description.
-
#item_files ⇒ Object
Returns the value of attribute item_files.
-
#name ⇒ Object
Returns the value of attribute name.
-
#root ⇒ Object
Returns the value of attribute root.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #apply_all ⇒ Object
- #apply_missing ⇒ Object
- #item(id) ⇒ Object
- #items ⇒ Object
- #sorted_items ⇒ Object
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
5 6 7 |
# File 'lib/protopack/package.rb', line 5 def end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/protopack/package.rb', line 4 def description @description end |
#item_files ⇒ Object
Returns the value of attribute item_files.
6 7 8 |
# File 'lib/protopack/package.rb', line 6 def item_files @item_files end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/protopack/package.rb', line 2 def name @name end |
#root ⇒ Object
Returns the value of attribute root.
7 8 9 |
# File 'lib/protopack/package.rb', line 7 def root @root end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/protopack/package.rb', line 3 def title @title end |
Class Method Details
.all ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/protopack/package.rb', line 47 def self.all Dir.glob("#{config_root}/*/package-config.yml").map { |pkg_cfg| cfg = YAML.load(File.read(pkg_cfg)) root = File.dirname pkg_cfg cfg["item_files"] = Dir.glob("#{root}/*item*.yml") cfg["root"] = root new cfg } end |
.config_root ⇒ Object
43 44 45 |
# File 'lib/protopack/package.rb', line 43 def self.config_root @@config_root end |
.config_root=(root) ⇒ Object
39 40 41 |
# File 'lib/protopack/package.rb', line 39 def self.config_root= root @@config_root = root end |
.find(name) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/protopack/package.rb', line 57 def self.find name root = "#{config_root}/#{name}" cfg = YAML.load(File.read("#{root}/package-config.yml")) cfg["item_files"] = Dir.glob("#{root}/*item*.yml") cfg["root"] = root new cfg end |
Instance Method Details
#apply_all ⇒ Object
26 27 28 29 30 |
# File 'lib/protopack/package.rb', line 26 def apply_all items = sorted_items items = items.select { |i| yield i } if block_given? items.each(&:apply!) end |
#apply_missing ⇒ Object
20 21 22 23 24 |
# File 'lib/protopack/package.rb', line 20 def apply_missing items = sorted_items.select(&:missing?) items = items.select { |i| yield i } if block_given? items.each(&:apply!) end |
#item(id) ⇒ Object
14 15 16 17 18 |
# File 'lib/protopack/package.rb', line 14 def item id items.each do |item| return item if (item.id == id) end end |
#items ⇒ Object
10 11 12 |
# File 'lib/protopack/package.rb', line 10 def items item_files.map { |item_file| Protopack::PackageItem.load(item_file) } end |
#sorted_items ⇒ Object
32 33 34 35 36 37 |
# File 'lib/protopack/package.rb', line 32 def sorted_items items.sort { |a, b| a, b = a.ordinal, b.ordinal a ? (b ? a <=> b : -1) : (b ? 1 : 0) } end |