protopack 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -89,7 +89,9 @@ names to items, if l10n is a concern: "widget-item.fr.yml", for example.
89
89
 
90
90
  Each *-item.yml contains at least three keys: "id", "type" and "attributes". Protopack calls #constantize
91
91
  on the "type" value in order to get a reference to the target class. The "attributes" are then
92
- passed to your #existence method as described above.
92
+ passed to your #existence method as described above. If you specify an "ordinal" key, it must be
93
+ numeric, and both Package#apply_all and Package#apply_missing will apply items after sorting by
94
+ #ordinal, putting nil ordinals last.
93
95
 
94
96
  You can add other keys that you might find useful for selecting and presenting items, for example, a
95
97
  "locale" key to show only items in the current user's locale.
@@ -22,13 +22,18 @@ class Protopack::Package
22
22
  end
23
23
 
24
24
  def apply_missing
25
- items.each do |item|
26
- item.apply! if item.missing?
27
- end
25
+ sorted_items.select(&:missing?).each &:apply!
28
26
  end
29
27
 
30
28
  def apply_all
31
- items.each &:apply!
29
+ sorted_items.each &:apply!
30
+ end
31
+
32
+ def sorted_items
33
+ items.sort { |a, b|
34
+ a, b = a.ordinal, b.ordinal
35
+ a ? (b ? a <=> b : -1) : (b ? 1 : 0)
36
+ }
32
37
  end
33
38
 
34
39
  def self.config_root= root
@@ -1,3 +1,3 @@
1
1
  module Protopack
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -32,33 +32,37 @@ describe Protopack::Package do
32
32
  p = Protopack::Package.find("standard-widgets")
33
33
  p.apply_all
34
34
 
35
- Widget.all.map(&:colour).should == %w{ blue green red}
35
+ Widget.all.map(&:colour).should == %w{ red blue yellow green black }
36
36
  end
37
37
 
38
- it "should install all items from a package, overwriting existing items" do
38
+ it "should install all items from a package, overwriting existing items, respecting #ordinal property" do
39
39
  Widget.new :colour => "blue"
40
40
  Widget.new :colour => "green"
41
41
 
42
42
  p = Protopack::Package.find("standard-widgets")
43
43
  p.apply_all
44
44
 
45
- Widget.all.map(&:colour).should == %w{ blue green red}
45
+ Widget.all.map(&:colour).should == %w{ blue green red yellow black }
46
46
  Widget.all[0].height.should == 'elephant'
47
47
  Widget.all[1].height.should == 'zebra'
48
48
  Widget.all[2].height.should == 'tiger'
49
+ Widget.all[3].height.should == 'hyena'
50
+ Widget.all[4].height.should == 'camel'
49
51
  end
50
52
 
51
53
  it "should install only missing items from a package, not overwriting existing items" do
52
- Widget.new :colour => "blue"
53
- Widget.new :colour => "green"
54
+ Widget.new :colour => "blue", :height => "not specified"
55
+ Widget.new :colour => "green", :height => "not specified"
54
56
 
55
57
  p = Protopack::Package.find("standard-widgets")
56
58
  p.apply_missing
57
59
 
58
- Widget.all.map(&:colour).should == %w{ blue green red}
59
- Widget.all[0].height.should == nil
60
- Widget.all[1].height.should == nil
60
+ Widget.all.map(&:colour).should == %w{ blue green red yellow black}
61
+ Widget.all[0].height.should == "not specified"
62
+ Widget.all[1].height.should == "not specified"
61
63
  Widget.all[2].height.should == 'tiger'
64
+ Widget.all[3].height.should == 'hyena'
65
+ Widget.all[4].height.should == 'camel'
62
66
  end
63
67
 
64
68
  end
@@ -0,0 +1,6 @@
1
+ id: black-widget
2
+ type: Widget
3
+ attributes:
4
+ colour: black
5
+ height: camel
6
+ density: rhetorical
@@ -1,5 +1,6 @@
1
- id: blue-widget
2
- type: Widget
1
+ id: blue-widget
2
+ type: Widget
3
+ ordinal: 2
3
4
  attributes:
4
5
  colour: blue
5
6
  height: elephant
@@ -1,5 +1,6 @@
1
- id: red-widget
2
- type: Widget
1
+ id: red-widget
2
+ type: Widget
3
+ ordinal: 1
3
4
  attributes:
4
5
  colour: red
5
6
  height: tiger
@@ -0,0 +1,7 @@
1
+ id: yellow-widget
2
+ type: Widget
3
+ ordinal: 99
4
+ attributes:
5
+ colour: yellow
6
+ height: hyena
7
+ density: occasional
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protopack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-15 00:00:00.000000000 Z
12
+ date: 2013-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -65,10 +65,12 @@ files:
65
65
  - spec/protopack/packages/advanced-widgets/lavender-widget-item.yml
66
66
  - spec/protopack/packages/advanced-widgets/magenta-widget-item.yml
67
67
  - spec/protopack/packages/advanced-widgets/package-config.yml
68
+ - spec/protopack/packages/standard-widgets/black-widget-item.yml
68
69
  - spec/protopack/packages/standard-widgets/blue-widget-item.yml
69
70
  - spec/protopack/packages/standard-widgets/green-widget-item.yml
70
71
  - spec/protopack/packages/standard-widgets/package-config.yml
71
72
  - spec/protopack/packages/standard-widgets/red-widget-item.yml
73
+ - spec/protopack/packages/standard-widgets/yellow-widget-item.yml
72
74
  - spec/spec_helper.rb
73
75
  homepage: ''
74
76
  licenses: []
@@ -100,8 +102,10 @@ test_files:
100
102
  - spec/protopack/packages/advanced-widgets/lavender-widget-item.yml
101
103
  - spec/protopack/packages/advanced-widgets/magenta-widget-item.yml
102
104
  - spec/protopack/packages/advanced-widgets/package-config.yml
105
+ - spec/protopack/packages/standard-widgets/black-widget-item.yml
103
106
  - spec/protopack/packages/standard-widgets/blue-widget-item.yml
104
107
  - spec/protopack/packages/standard-widgets/green-widget-item.yml
105
108
  - spec/protopack/packages/standard-widgets/package-config.yml
106
109
  - spec/protopack/packages/standard-widgets/red-widget-item.yml
110
+ - spec/protopack/packages/standard-widgets/yellow-widget-item.yml
107
111
  - spec/spec_helper.rb