chef-sugar 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f20f8de1e2ae7d007959739a79232f17f9c77ab8
4
- data.tar.gz: c8a6790c44827d8f3423f0824cf87c47901cc306
3
+ metadata.gz: 75de0550f84f3b8ef3b94926f60c2b3a7a757c02
4
+ data.tar.gz: 081a7e696179a33958fe4a38cf7022da9c8c0d0b
5
5
  SHA512:
6
- metadata.gz: 0449dc8267586cffc7699139e1d0aaad5f7bac5f79994b6ea8e5fc5e6719f779084852ba351341bc23009d995357f5f3aa277a27d400e85c0d9c1fc829c90384
7
- data.tar.gz: 918e1e5c4f02c7e20d353a2b0dd891c204996b6e8a261c01ef16d0fbe67c3fa25929af83850fddee106858d69c99442f50e3bc97e621d2749f5cd4ace2884aa4
6
+ metadata.gz: f506eb432d8a39cfdea1b709fe760c9994887655503cb2e539bc1ffe5e299d49513a4a0f3928b1ac02e8c42e453726979df4f76d4c2f3c2f69a9d5b663fc337d
7
+ data.tar.gz: d6e52403bf24e0a37b61432373b455806d563004773a757fc2d61eff4103e4dbe89796ede0c3d67eea01ab332cdf63d64f25f9c429ea367f6367ec9bb8294983
data/.kitchen.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  driver_plugin: vagrant
2
2
  driver_config:
3
3
  require_chef_omnibus: true
4
+ synced_folders:
5
+ - ['<%= File.expand_path('..', __FILE__) %>', '/gem']
4
6
 
5
7
  platforms:
6
8
  # - name: ubuntu-10.04
@@ -11,4 +13,4 @@ platforms:
11
13
  suites:
12
14
  - name: install
13
15
  run_list:
14
- - recipe[chef-sugar::default]
16
+ - recipe[chef-sugar::development]
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  rvm:
2
- - 1.9.1
2
+ - 1.9.3
3
3
  - 2.0.0
4
4
  script:
5
5
  - bundle exec rspec --color --format progress
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@ Chef Sugar Changelog
2
2
  =========================
3
3
  This file is used to list changes made in each version of the chef-sugar cookbook and gem.
4
4
 
5
- v1.0.0 (TBD)
6
- ------------
5
+
6
+ v1.0.1 (2013-10-15)
7
+ -------------------
8
+ - Add development recipe
9
+ - Add `compile_time`, `before`, and `after` filters
10
+
11
+ v1.0.0 (2013-10-15)
12
+ -------------------
7
13
  - First public release
data/README.md CHANGED
@@ -175,6 +175,7 @@ end
175
175
  - `arch_linux?`
176
176
  - `debian?`
177
177
  - `fedora?`
178
+ - `freebsd?`
178
179
  - `gentoo?`
179
180
  - `linux?`
180
181
  - `mac_os_x?`
@@ -237,6 +238,35 @@ http_request 'http://...' do
237
238
  end
238
239
  ```
239
240
 
241
+ ### Filters
242
+ - `compile_time` - accepts a block of resources to run at compile time
243
+ - `before` - insert resource in the collection before the given resource
244
+ - `after` - insert resource in the collection after the given resource
245
+
246
+ #### Examples
247
+ ```ruby
248
+ compile_time do
249
+ package 'apache2'
250
+ end
251
+
252
+ # This is equivalent to
253
+ package 'apache2' do
254
+ 'apache2'
255
+ end.run_action(:install)
256
+ ```
257
+
258
+ ```ruby
259
+ before 'service[apache2]' do
260
+ log 'I am before the apache 2 service fires!'
261
+ end
262
+ ```
263
+
264
+ ```ruby
265
+ after 'service[apache2]' do
266
+ log 'I am after the apache 2 service fires!'
267
+ end
268
+ ```
269
+
240
270
 
241
271
  License & Authors
242
272
  -----------------
data/lib/chef/sugar.rb CHANGED
@@ -22,6 +22,7 @@ class Chef
22
22
  module Sugar
23
23
  require_relative 'sugar/architecture'
24
24
  require_relative 'sugar/cloud'
25
+ require_relative 'sugar/filters'
25
26
  require_relative 'sugar/ip'
26
27
  require_relative 'sugar/node'
27
28
  require_relative 'sugar/platform'
@@ -0,0 +1,147 @@
1
+ class Chef
2
+ module Sugar
3
+ module Filters
4
+ #
5
+ # Evaluate resources at compile time instead of converge time.
6
+ #
7
+ class CompileTime
8
+ def initialize(recipe)
9
+ @recipe = recipe
10
+ end
11
+
12
+ def evaluate(&block)
13
+ instance_eval(&block)
14
+ end
15
+
16
+ def method_missing(m, *args, &block)
17
+ resource = @recipe.send(m, *args, &block)
18
+ actions = Array(resource.action)
19
+ resource.action(:nothing)
20
+ actions.each do |action|
21
+ resource.run_action(action)
22
+ end
23
+ end
24
+ end
25
+
26
+ #
27
+ # A top-level class for manipulation the resource collection.
28
+ #
29
+ class Injector
30
+ def initialize(recipe, identifier, placement)
31
+ @recipe = recipe
32
+ @resource_collection = @recipe.run_context.resource_collection
33
+ @resource = @resource_collection.lookup(identifier)
34
+ @placement = placement
35
+ end
36
+
37
+ def evaluate(&block)
38
+ instance_eval(&block)
39
+ end
40
+
41
+ def insert_before(resource, new_resource)
42
+ @resource_collection.instance_eval do
43
+ # Remove the resource because it's automatically created
44
+ @resources.delete_at(@resources_by_name[new_resource.to_s])
45
+ @resources_by_name.delete(new_resource.to_s)
46
+
47
+ index = @resources_by_name[resource.to_s]
48
+ @resources.insert(index, new_resource)
49
+ @resources_by_name[new_resource.to_s] = index
50
+ end
51
+ end
52
+
53
+ def insert_after(resource, new_resource)
54
+ @resource_collection.instance_eval do
55
+ # Remove the resource because it's automatically created
56
+ @resources.delete_at(@resources_by_name[new_resource.to_s])
57
+ @resources_by_name.delete(new_resource.to_s)
58
+
59
+ index = @resources_by_name[resource.to_s] + 2
60
+ @resources.insert(index, new_resource)
61
+ @resources_by_name[new_resource.to_s] = index
62
+ end
63
+ end
64
+
65
+ def method_missing(m, *args, &block)
66
+ new_resource = @recipe.send(m, *args, &block)
67
+
68
+ case @placement
69
+ when :before
70
+ insert_before(@resource, new_resource)
71
+ when :after
72
+ insert_after(@resource, new_resource)
73
+ else
74
+ super
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ module DSL
81
+ #
82
+ # Dynamically run resources specified in the block during the compilation
83
+ # phase, instead of the convergence phase.
84
+ #
85
+ # @example The old way
86
+ # package('apache2') do
87
+ # action :nothing
88
+ # end.run_action(:install)
89
+ #
90
+ # @example The new way
91
+ # compile_time do
92
+ # package('apache2')
93
+ # end
94
+ #
95
+ # @example Resource actions are run in order
96
+ # compile_time do
97
+ # service 'apache2' do
98
+ # action [:enable, :start] # run_action(:enable), run_action(:start)
99
+ # end
100
+ # end
101
+ #
102
+ def compile_time(&block)
103
+ Chef::Sugar::Filters::CompileTime.new(self).evaluate(&block)
104
+ end
105
+
106
+ #
107
+ # Dynamically insert resources before an existing resource in the
108
+ # resource_collection.
109
+ #
110
+ # @example Write a custom template before the apache2 service actions
111
+ # are run
112
+ # before 'service[apache2]' do
113
+ # template '/etc/apache2/thing.conf' do
114
+ # source '...'
115
+ # end
116
+ # end
117
+ #
118
+ #
119
+ # @param [String] identifier
120
+ # the +resource[name]+ identifier string
121
+ #
122
+ def before(identifier, &block)
123
+ Chef::Sugar::Filters::Injector.new(self, identifier, :before).evaluate(&block)
124
+ end
125
+
126
+ #
127
+ # Dynamically insert resources after an existing resource in the
128
+ # resource_collection.
129
+ #
130
+ # @example Write a custom template after the apache2 service actions
131
+ # are run
132
+ # after 'service[apache2]' do
133
+ # template '/etc/apache2/thing.conf' do
134
+ # source '...'
135
+ # end
136
+ # end
137
+ #
138
+ #
139
+ # @param [String] identifier
140
+ # the +resource[name]+ identifier string
141
+ #
142
+ def after(identifier, &block)
143
+ Chef::Sugar::Filters::Injector.new(self, identifier, :after).evaluate(&block)
144
+ end
145
+ end
146
+ end
147
+ end
@@ -53,6 +53,17 @@ class Chef
53
53
  node['platform_family'] == 'fedora'
54
54
  end
55
55
 
56
+ #
57
+ # Determine if the current node is a member of the freebsd family.
58
+ #
59
+ # @param [Chef::Node] node
60
+ #
61
+ # @return [Boolean]
62
+ #
63
+ def freebsd?(node)
64
+ node['platform_family'] == 'freebsd'
65
+ end
66
+
56
67
  #
57
68
  # Determine if the current node is a member of the arch family.
58
69
  #
@@ -16,6 +16,6 @@
16
16
 
17
17
  class Chef
18
18
  module Sugar
19
- VERSION = '1.0.0'
19
+ VERSION = '1.0.1'
20
20
  end
21
21
  end
data/metadata.rb CHANGED
@@ -5,4 +5,4 @@ license 'Apache 2.0'
5
5
  description 'Installs chef-sugar. Please see the chef-sugar ' \
6
6
  'Ruby gem for more information.'
7
7
  long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
8
- version '1.0.0'
8
+ version '1.0.1'
data/recipes/default.rb CHANGED
@@ -18,7 +18,7 @@
18
18
  #
19
19
 
20
20
  chef_gem('chef-sugar') do
21
- version '1.0.0'
21
+ version '1.0.1'
22
22
  action :nothing
23
23
  end.run_action(:install)
24
24
 
@@ -0,0 +1,65 @@
1
+ #
2
+ # Cookbook Name:: chef-sugar
3
+ # Recipe:: development
4
+ #
5
+ # Copyright 2013, Seth Vargo <sethvargo@gmail.com>
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ #
21
+ # This recipe is only meant for use when developing Chef Sugar.
22
+ #
23
+
24
+ execute('apt-get update') do
25
+ only_if { Time.now.to_i - 86400 > `stat -c %Y /var/cache/apt/`.to_i }
26
+ end.run_action(:run)
27
+
28
+ [
29
+ 'build-essential',
30
+ 'libxslt-dev',
31
+ 'libxml2-dev',
32
+ 'git'
33
+ ].each do |name|
34
+ package(name) do
35
+ action :nothing
36
+ end.run_action(:install)
37
+ end
38
+
39
+ execute('gem update bundler') do
40
+ action :nothing
41
+ not_if { `bundle -v`.strip.gsub(/[^0-9\.]/, '').to_f >= 1.3 }
42
+ end.run_action(:run)
43
+
44
+ execute 'bundle[chef-sugar]' do
45
+ cwd '/gem'
46
+ command 'bundle install --path vendor'
47
+ not_if 'bundle check --gemfile /gem/Gemfile'
48
+ action :nothing
49
+ end.run_action(:run)
50
+
51
+ execute 'build[chef-sugar]' do
52
+ cwd '/gem'
53
+ command 'bundle exec rake build'
54
+ action :nothing
55
+ end.run_action(:run)
56
+
57
+ sugar = chef_gem('chef-sugar') do
58
+ source '/gem/pkg/chef-sugar-1.0.0.gem'
59
+ action :nothing
60
+ end
61
+
62
+ sugar.run_action(:remove)
63
+ sugar.run_action(:install)
64
+
65
+ require 'chef/sugar'
@@ -39,6 +39,18 @@ describe Chef::Sugar::PlatformFamily do
39
39
  end
40
40
  end
41
41
 
42
+ describe '#freebsd?' do
43
+ it 'returns true when the platform_family is freebsd' do
44
+ node = { 'platform_family' => 'freebsd' }
45
+ expect(described_class.freebsd?(node)).to be_true
46
+ end
47
+
48
+ it 'returns false when the platform_family is not freebsd' do
49
+ node = { 'platform_family' => 'windows' }
50
+ expect(described_class.freebsd?(node)).to be_false
51
+ end
52
+ end
53
+
42
54
  describe '#gentoo?' do
43
55
  it 'returns true when the platform_family is gentoo' do
44
56
  node = { 'platform_family' => 'gentoo' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-sugar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
@@ -144,6 +144,7 @@ files:
144
144
  - lib/chef/sugar.rb
145
145
  - lib/chef/sugar/architecture.rb
146
146
  - lib/chef/sugar/cloud.rb
147
+ - lib/chef/sugar/filters.rb
147
148
  - lib/chef/sugar/ip.rb
148
149
  - lib/chef/sugar/node.rb
149
150
  - lib/chef/sugar/platform.rb
@@ -154,6 +155,7 @@ files:
154
155
  - lib/chef/sugar/version.rb
155
156
  - metadata.rb
156
157
  - recipes/default.rb
158
+ - recipes/development.rb
157
159
  - spec/spec_helper.rb
158
160
  - spec/support/shared_examples.rb
159
161
  - spec/unit/chef/extensions/architecture_spec.rb