protopack 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,8 +13,14 @@ class Protopack::PackageItem
13
13
  attributes.name
14
14
  end
15
15
 
16
+ def lookup_class base, list
17
+ base = base.const_get list.shift
18
+ return base if list.empty?
19
+ lookup_class base, list
20
+ end
21
+
16
22
  def target_class
17
- Kernel.const_get type
23
+ lookup_class Kernel, type.split("::")
18
24
  end
19
25
 
20
26
  def missing?
@@ -1,3 +1,3 @@
1
1
  module Protopack
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/models.rb ADDED
@@ -0,0 +1,81 @@
1
+ class Repository
2
+ def initialize klass, name
3
+ @klass, @name = klass, name
4
+ end
5
+
6
+ def create! attributes
7
+ @klass.new(attributes)
8
+ end
9
+
10
+ def matches
11
+ @klass.all.select { |w| w.colour == @name }
12
+ end
13
+
14
+ def empty?
15
+ matches.empty?
16
+ end
17
+
18
+ def first
19
+ matches.first
20
+ end
21
+ end
22
+
23
+ class Widget
24
+ @@widgets = []
25
+
26
+ def self.all
27
+ @@widgets
28
+ end
29
+
30
+ def self.destroy_all
31
+ @@widgets = []
32
+ end
33
+
34
+ def initialize attrs
35
+ @attrs = attrs.is_a?(Hash) ? Hashie::Mash.new(attrs) : attrs
36
+ @@widgets << self
37
+ end
38
+
39
+ def method_missing m, *args
40
+ @attrs.send m, *args
41
+ end
42
+
43
+ def update_attributes attrs
44
+ @attrs = attrs
45
+ end
46
+
47
+ def self.existence attrs
48
+ Repository.new Widget, attrs.colour
49
+ end
50
+ end
51
+
52
+ module Wot
53
+ class Zit
54
+ @@wotzits = []
55
+
56
+ def self.all
57
+ @@wotzits
58
+ end
59
+
60
+ def self.destroy_all
61
+ @@wotzits = []
62
+ end
63
+
64
+ def initialize attrs
65
+ @attrs = attrs.is_a?(Hash) ? Hashie::Mash.new(attrs) : attrs
66
+ @@wotzits << self
67
+ end
68
+
69
+ def method_missing m, *args
70
+ @attrs.send m, *args
71
+ end
72
+
73
+ def update_attributes attrs
74
+ @attrs = attrs
75
+ end
76
+
77
+ def self.existence attrs
78
+ Repository.new Wot::Zit, attrs.colour
79
+ end
80
+ end
81
+ end
@@ -7,6 +7,7 @@ describe Protopack::Package do
7
7
  before {
8
8
  Protopack::Package.config_root = File.expand_path('../packages', __FILE__)
9
9
  Widget.destroy_all
10
+ Wot::Zit.destroy_all
10
11
  }
11
12
 
12
13
  it "should find all the packages" do
@@ -65,4 +66,10 @@ describe Protopack::Package do
65
66
  Widget.all[4].height.should == 'camel'
66
67
  end
67
68
 
69
+ it "looks up namespaced class names" do
70
+ p = Protopack::Package.find("advanced-widgets")
71
+ p.apply_missing
72
+
73
+ Wot::Zit.all.map(&:colour).should == %w{ lavender magenta }
74
+ end
68
75
  end
@@ -1,5 +1,5 @@
1
- name: lavender-widget
2
- type: Widget
1
+ name: lavender-wotzit
2
+ type: Wot::Zit
3
3
  attributes:
4
4
  colour: lavender
5
5
  height: trapeze
@@ -1,5 +1,5 @@
1
- name: magenta-widget
2
- type: Widget
1
+ name: magenta-wotzit
2
+ type: Wot::Zit
3
3
  attributes:
4
4
  colour: magenta
5
5
  height: hippopotamus
data/spec/spec_helper.rb CHANGED
@@ -23,53 +23,5 @@ RSpec.configure do |config|
23
23
  config.order = 'random'
24
24
  end
25
25
 
26
- class Widget
27
- @@widgets = []
26
+ load(File.dirname(__FILE__) + '/models.rb')
28
27
 
29
- def self.all
30
- @@widgets
31
- end
32
-
33
- def self.destroy_all
34
- @@widgets = []
35
- end
36
-
37
- def initialize attrs
38
- @attrs = attrs.is_a?(Hash) ? Hashie::Mash.new(attrs) : attrs
39
- @@widgets << self
40
- end
41
-
42
- def method_missing m, *args
43
- @attrs.send m, *args
44
- end
45
-
46
- def update_attributes attrs
47
- @attrs = attrs
48
- end
49
-
50
- def self.existence attrs
51
- WidgetRepository.new attrs.colour
52
- end
53
- end
54
-
55
- class WidgetRepository
56
- def initialize name
57
- @name = name
58
- end
59
-
60
- def create! attributes
61
- Widget.new(attributes)
62
- end
63
-
64
- def matches
65
- Widget.all.select { |w| w.colour == @name }
66
- end
67
-
68
- def empty?
69
- matches.empty?
70
- end
71
-
72
- def first
73
- matches.first
74
- end
75
- end
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -61,6 +61,7 @@ files:
61
61
  - lib/protopack/package_item.rb
62
62
  - lib/protopack/version.rb
63
63
  - protopack.gemspec
64
+ - spec/models.rb
64
65
  - spec/protopack/package_spec.rb
65
66
  - spec/protopack/packages/advanced-widgets/lavender-widget-item.yml
66
67
  - spec/protopack/packages/advanced-widgets/magenta-widget-item.yml
@@ -98,6 +99,7 @@ specification_version: 3
98
99
  summary: Store packages of object prototypes on-disk as YML; this gem allows you scan
99
100
  each package for missing items and apply them to your repository.
100
101
  test_files:
102
+ - spec/models.rb
101
103
  - spec/protopack/package_spec.rb
102
104
  - spec/protopack/packages/advanced-widgets/lavender-widget-item.yml
103
105
  - spec/protopack/packages/advanced-widgets/magenta-widget-item.yml