hibachi 0.0.1.pre → 0.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93d51833915516bde538031d378a015bcac41b0d
4
- data.tar.gz: ca5f2c393ab648c57a620a2f74b2f30fbecb64d7
3
+ metadata.gz: 54dc5e3824748620f18d9f3042b2ddd98416a874
4
+ data.tar.gz: 245a686100d27ee774ef1c4f9bd0d56b113c4d66
5
5
  SHA512:
6
- metadata.gz: 6cfc2e1dec973836c824094c604d5c338274eb9883f59ef5fb2e2feedc67056b7e743e0a24770f2f11ccd8629d9b7c9ac5fc66966a8d81e677f6d718d8095d1b
7
- data.tar.gz: 19c4b64c853cbe399769e6a8759e7c8c4aca6263da7d53258918711cee39784e4c7c1d274d33f86c015926ee077795c65ac9cb866138631cab298015f84bdd08
6
+ metadata.gz: 1f0070bd2bf79c7c7e33d2374c04cdc0cf1b8f2bb9938d008cb345c14aca44b0991ec7b14f6b5ba73ad1930487f6b97c4f4299e2741710910e0da499985ef219
7
+ data.tar.gz: 56b4d417289b1ee8579056eaeb9477d896b937396041e819382249719e0e42a4a99938e75bda9b9c5d164a29f49d3cb3109d285696d2e3e578d363a3408675a4
@@ -11,7 +11,7 @@ module Hibachi
11
11
  include ActiveModel::Model
12
12
  include Enumerable
13
13
 
14
- attr_accessor :attributes, :file_path
14
+ attr_accessor :file_path
15
15
 
16
16
  validates :file_path, presence: true
17
17
 
@@ -45,7 +45,7 @@ module Hibachi
45
45
  attributes[key]
46
46
  end
47
47
 
48
- # Set the attribute at a given key.
48
+ # Set the attribute at a given key and update the JSON.
49
49
  def []= key, value
50
50
  merge! key => value
51
51
  end
@@ -74,8 +74,10 @@ module Hibachi
74
74
  @attributes ||= parsed_json_attributes[Hibachi.config.cookbook] || {}
75
75
  end
76
76
 
77
- delegate :any?, :to => :attributes
78
- delegate :empty?, :to => :attributes
77
+ def method_missing(method, *arguments)
78
+ attributes.send method, *arguments if attributes.respond_to? method
79
+ super
80
+ end
79
81
 
80
82
  protected
81
83
  # All attributes as parsed from the Chef JSON.
@@ -1,6 +1,6 @@
1
1
  module Hibachi
2
2
  # Backend data store methods for the Hibachi::Model
3
- module Store
3
+ module Persistence
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  # Merge attrs and write to JSON.
@@ -1,5 +1,7 @@
1
1
  module Hibachi
2
2
  module Querying
3
+ include Enumerable
4
+
3
5
  # Write the given attrs to config and re-run Chef.
4
6
  def create from_attributes={}
5
7
  model = new from_attributes
@@ -13,6 +15,10 @@ module Hibachi
13
15
  node[recipe_name].map { |from_params| new from_params }
14
16
  end
15
17
 
18
+ def each
19
+ all.each { |model| yield model }
20
+ end
21
+
16
22
  # Find all objects of this type matching the given search
17
23
  # criteria. Uses the all() method to scope calls from within the
18
24
  # proper JSON for this class, and instantiates objects based on
@@ -13,8 +13,8 @@ module Hibachi
13
13
  # touch this name. By default, this creates a 'collection' recipe.
14
14
  def recipe name, options={}
15
15
  self.recipe_name = name
16
- from_opts = "#{options[:type]}" || 'collection'
17
- self.recipe_type = ActiveSupport::StringInquirer.new from_opts
16
+ from_opts = options[:type] || 'collection'
17
+ self.recipe_type = ActiveSupport::StringInquirer.new from_opts.to_s
18
18
  end
19
19
 
20
20
  # An alias for `recipe` to give parity to `singleton_recipe`.
@@ -38,11 +38,11 @@ module Hibachi
38
38
  # Return the recipe type as set in the class definition. It's a
39
39
  # StringInquirer, so it defines methods that allow us to test
40
40
  # whether this is a `collection?` or a `singleton?`.
41
- def type
41
+ def recipe_type
42
42
  self.class.recipe_type
43
43
  end
44
44
 
45
- delegate :collection?, :to => :type
46
- delegate :singleton?, :to => :type
45
+ delegate :collection?, :to => :recipe_type
46
+ delegate :singleton?, :to => :recipe_type
47
47
  end
48
48
  end
@@ -1,3 +1,3 @@
1
1
  module Hibachi
2
- VERSION = "0.0.1.pre"
2
+ VERSION = "0.0.1"
3
3
  end
@@ -1,7 +1,4 @@
1
1
  {
2
2
  "test": {
3
- "mock_settings": {
4
- "name": "store"
5
- }
6
3
  }
7
4
  }
@@ -13,12 +13,12 @@ module Hibachi
13
13
  end
14
14
 
15
15
  it "runs chef" do
16
- subject.stub(:run) { true }
16
+ allow(subject).to receive(:run).and_return true
17
17
  expect(subject.run_chef(:pro)).to eq(true)
18
18
  end
19
19
 
20
20
  it "runs chef in the background" do
21
- subject.stub(:run_chef_in_bg) { true }
21
+ allow(subject).to receive(:run_chef_in_bg).and_return true
22
22
  expect(subject.run_chef(:pro, background: true)).to eq(true)
23
23
  end
24
24
  end
@@ -1,9 +1,11 @@
1
1
  require 'spec_helper'
2
- require 'hibachi/store'
2
+ require 'hibachi/persistence'
3
3
 
4
4
  module Hibachi
5
- describe Store do
5
+ describe Persistence do
6
6
  it "creates a new model from scratch" do
7
+ expect(MockSetting.recipe_name).to eq(:mock_settings)
8
+ expect(MockSetting).to be_singleton
7
9
  setting = MockSetting.create(name: 'from-scratch')
8
10
  expect(setting).to be_persisted
9
11
  expect(setting.destroy).to eq(true)
@@ -3,30 +3,53 @@ require 'hibachi/recipe'
3
3
 
4
4
  module Hibachi
5
5
  describe Recipe do
6
- class MockForRecipe < Hibachi::Model
7
- recipe :name_of_recipe, :type => :singleton
6
+ context "with a singleton setting" do
7
+ subject { SingletonSetting }
8
8
 
9
- attr_accessor :name
10
- end
9
+ it "sets the recipe in the class definition" do
10
+ expect(subject.recipe_name).to eq(:singleton_settings)
11
+ end
11
12
 
12
- it "sets the recipe in the class definition" do
13
- expect(MockForRecipe.recipe_name).to eq(:name_of_recipe)
14
- end
13
+ it "sets the type of recipe in the class definition" do
14
+ expect(subject.recipe_type).to eq('singleton')
15
+ end
15
16
 
16
- it "sets the type of recipe in the class definition" do
17
- expect(MockForRecipe.recipe_type).to eq('singleton')
18
- end
17
+ it "is a singleton" do
18
+ expect(subject).to be_singleton
19
+ end
19
20
 
20
- it "is a singleton" do
21
- expect(MockForRecipe).to be_singleton
21
+ context "with an instantiated setting" do
22
+ let(:setting) { subject.new name: 'test' }
23
+
24
+ it "is a singleton" do
25
+ expect(setting).to be_singleton
26
+ end
27
+ end
22
28
  end
23
29
 
24
- context "with an instantiated singleton" do
25
- subject { MockForRecipe.new name: 'test' }
30
+ context "with a collection setting" do
31
+ subject { MockSetting }
26
32
 
27
- it "is a singleton" do
28
- expect(subject).to be_singleton
33
+ it "sets the recipe in the class definition" do
34
+ expect(subject.recipe_name).to eq(:mock_settings)
35
+ end
36
+
37
+ it "sets the type of recipe in the class definition" do
38
+ expect(subject.recipe_type).to eq('collection')
39
+ end
40
+
41
+ it "is a collection" do
42
+ expect(subject).to be_collection
43
+ end
44
+
45
+ context "with an instantiated setting" do
46
+ let(:setting) { subject.new name: 'test' }
47
+
48
+ it "is a collection" do
49
+ expect(setting).to be_collection
50
+ end
29
51
  end
30
52
  end
53
+
31
54
  end
32
55
  end
@@ -1,10 +1,9 @@
1
1
  require 'hibachi'
2
2
 
3
3
  class MockSetting < Hibachi::Model
4
-
5
4
  recipe :mock_settings
6
5
 
7
- attr_accessor :attributes, :name, :is_active
6
+ attr_accessor :name, :is_active
8
7
 
9
8
  validates :name, :presence => true
10
9
 
@@ -0,0 +1,5 @@
1
+ class SingletonSetting < Hibachi::Model
2
+ recipe :singleton_settings, :type => :singleton
3
+
4
+ attr_accessor :name
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hibachi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Scott
@@ -214,12 +214,13 @@ files:
214
214
  - spec/hibachi/configuration_spec.rb
215
215
  - spec/hibachi/model_spec.rb
216
216
  - spec/hibachi/node_spec.rb
217
+ - spec/hibachi/persistence_spec.rb
217
218
  - spec/hibachi/recipe_spec.rb
218
- - spec/hibachi/store_spec.rb
219
219
  - spec/hibachi_spec.rb
220
220
  - spec/spec_helper.rb
221
221
  - spec/support/mock_setting.rb
222
222
  - spec/support/mock_singleton.rb
223
+ - spec/support/singleton_setting.rb
223
224
  homepage: http://github.com/tubbo/hibachi
224
225
  licenses:
225
226
  - NCSA
@@ -235,9 +236,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
235
236
  version: '0'
236
237
  required_rubygems_version: !ruby/object:Gem::Requirement
237
238
  requirements:
238
- - - '>'
239
+ - - '>='
239
240
  - !ruby/object:Gem::Version
240
- version: 1.3.1
241
+ version: '0'
241
242
  requirements: []
242
243
  rubyforge_project:
243
244
  rubygems_version: 2.0.3
@@ -290,10 +291,11 @@ test_files:
290
291
  - spec/hibachi/configuration_spec.rb
291
292
  - spec/hibachi/model_spec.rb
292
293
  - spec/hibachi/node_spec.rb
294
+ - spec/hibachi/persistence_spec.rb
293
295
  - spec/hibachi/recipe_spec.rb
294
- - spec/hibachi/store_spec.rb
295
296
  - spec/hibachi_spec.rb
296
297
  - spec/spec_helper.rb
297
298
  - spec/support/mock_setting.rb
298
299
  - spec/support/mock_singleton.rb
300
+ - spec/support/singleton_setting.rb
299
301
  has_rdoc: