Class: Protopack::Package

Inherits:
Aduki::Initializable
  • Object
show all
Defined in:
lib/protopack/package.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorsObject

Returns the value of attribute authors.



5
6
7
# File 'lib/protopack/package.rb', line 5

def authors
  @authors
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/protopack/package.rb', line 4

def description
  @description
end

#item_filesObject

Returns the value of attribute item_files.



6
7
8
# File 'lib/protopack/package.rb', line 6

def item_files
  @item_files
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/protopack/package.rb', line 2

def name
  @name
end

#rootObject

Returns the value of attribute root.



7
8
9
# File 'lib/protopack/package.rb', line 7

def root
  @root
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/protopack/package.rb', line 3

def title
  @title
end

Class Method Details

.allObject



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_rootObject



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_allObject



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_missingObject



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

#itemsObject



10
11
12
# File 'lib/protopack/package.rb', line 10

def items
  item_files.map { |item_file| Protopack::PackageItem.load(item_file) }
end

#sorted_itemsObject



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