linecook 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History CHANGED
@@ -1,3 +1,10 @@
1
+ == 1.2.0 2011/05/23
2
+
3
+ * updated to run on 1.9.2, jruby
4
+ * allow build of recipes without a package file
5
+ * added Recipe#close! to unregister a recipe from a package
6
+ * allow .yml,.yaml,.json attributes files
7
+
1
8
  == 1.1.0 2011/05/02
2
9
 
3
10
  * updated scaffold generated by 'linecook init' to be current and simpler
@@ -19,17 +19,17 @@ module Linecook
19
19
  sources = {}
20
20
  helpers = []
21
21
 
22
- Dir.glob("#{helpers_dir}/*/**/*").each do |source|
23
- next if File.directory?(source)
24
- (sources[File.dirname(source)] ||= []) << source
22
+ Dir.glob("#{helpers_dir}/*/**/*").each do |source_file|
23
+ next if File.directory?(source_file)
24
+ (sources[File.dirname(source_file)] ||= []) << source_file
25
25
  end
26
26
 
27
- sources.each_pair do |dir, sources|
27
+ sources.each_pair do |dir, source_files|
28
28
  name = dir[(helpers_dir.length + 1)..-1]
29
- helpers << [name, sources]
29
+ helpers << [name, source_files]
30
30
  end
31
31
 
32
- helpers.sort_by {|name, sources| name }
32
+ helpers.sort_by {|name, source_files| name }
33
33
  end
34
34
 
35
35
  def glob_package_files(package_names)
@@ -211,7 +211,7 @@ module Linecook
211
211
  compiler = ERB::Compiler.new('<>')
212
212
  compiler.put_cmd = "write"
213
213
  compiler.insert_cmd = "write"
214
- code = compiler.compile(body)
214
+ code = [compiler.compile(body)].flatten.first
215
215
 
216
216
  "#{source}\n#{code}".gsub(/^(\s*)/) do |m|
217
217
  indent = 2 + $1.length - ($1.length % 2)
@@ -274,11 +274,11 @@ DOC
274
274
  DEFINITION_TEMPLATE_LINE = __LINE__ + 2
275
275
  DEFINITION_TEMPLATE = ERB.new(<<-DOC, nil, '<>').src
276
276
  <%= sections['head'] %>
277
- <% definitions.each do |desc, method_name, signature, body| %>
277
+ <% definitions.each do |desc, method_name, signature, method_body| %>
278
278
  <% desc.split("\n").each do |line| %>
279
279
  # <%= line %><% end %>
280
280
  def <%= method_name %><%= signature %>
281
- <%= body %>
281
+ <%= method_body %>
282
282
 
283
283
  chain_proxy
284
284
  end
@@ -46,7 +46,7 @@ module Linecook
46
46
  context = OpenStruct.new(
47
47
  :project_name => project_name,
48
48
  :const_name => Utils.camelize(project_name)
49
- ).send(:binding)
49
+ ).instance_eval('binding')
50
50
 
51
51
  #
52
52
  # Copy template files into place
@@ -12,14 +12,14 @@ module Linecook
12
12
  config :hosts, false, :short => :n, &c.flag # print state by host
13
13
 
14
14
  def state(vm_name)
15
- running?(vm_name) ? "running" : "stopped"
15
+ `VBoxManage showvminfo #{vm_name}` =~ /^State:\s+(.*)$/ ? $1 : 'unknown'
16
16
  end
17
17
 
18
18
  def process(*hosts)
19
19
  vm_names = resolve_vm_names(hosts)
20
20
  if hosts
21
21
  each_host(vm_names) do |host|
22
- puts "#{host}: #{state(host_map[host])}"
22
+ puts "#{host}: #{state(host_map[host] || host)}"
23
23
  end
24
24
  else
25
25
  each_vm_name(vm_names) do |vm_name|
@@ -57,7 +57,7 @@ module Linecook
57
57
  end
58
58
 
59
59
  def resolve_vm_names(hosts)
60
- names ? hosts : hosts.collect {|host| host_map[host] }
60
+ names ? hosts : hosts.collect {|host| host_map[host] || host }
61
61
  end
62
62
 
63
63
  def each_host(hosts=[])
@@ -197,14 +197,29 @@ module Linecook
197
197
  resource_path('recipes', recipe_name)
198
198
  end
199
199
 
200
- # Loads the attributes file with the specified name and evaluates in the
201
- # context of Attributes. Returns the new Attributes object.
200
+ # Loads the named attributes file into and returns an instance of
201
+ # Attributes. The loading mechanism depends on the attributes file
202
+ # extname.
203
+ #
204
+ # .rb: evaluate in the context of attributes
205
+ # .yml,.yaml,.json: load as YAML and merge into attributes
206
+ #
207
+ # All other file types raise an error. Simply returns a new Attributes
208
+ # instance if no name is given.
202
209
  def load_attributes(attributes_name=nil)
203
210
  attributes = Attributes.new
204
211
 
205
212
  if attributes_name
206
213
  path = attributes_path(attributes_name)
207
- attributes.instance_eval(File.read(path), path)
214
+
215
+ case File.extname(path)
216
+ when '.rb'
217
+ attributes.instance_eval(File.read(path), path)
218
+ when '.yml', '.yaml', '.json'
219
+ attributes.attrs.merge!(YAML.load_file(path))
220
+ else
221
+ raise "invalid attributes format: #{path.inspect}"
222
+ end
208
223
  end
209
224
 
210
225
  attributes
@@ -81,6 +81,13 @@ module Linecook
81
81
  self
82
82
  end
83
83
 
84
+ # Closes _target_ and returns self, and unregisters _target_ from the
85
+ # package. Useful for recipes that only generate other files.
86
+ def close!
87
+ _package_.registry.delete _target_name_
88
+ close
89
+ end
90
+
84
91
  # Returns true if _target_ is closed.
85
92
  def closed?
86
93
  _target_.closed?
@@ -11,7 +11,7 @@ module Linecook
11
11
  end
12
12
 
13
13
  def build(locals={})
14
- erb.result OpenStruct.new(locals).send(:binding)
14
+ erb.result OpenStruct.new(locals).instance_eval('binding')
15
15
  end
16
16
  end
17
17
  end
@@ -1,3 +1,5 @@
1
+ require 'linecook/test/shim'
2
+
1
3
  module Linecook
2
4
  module Test
3
5
  module FileTest
@@ -1,5 +1,6 @@
1
1
  require 'linecook/test/regexp_escape'
2
2
  require 'linecook/test/command_parser'
3
+ require 'linecook/test/shim'
3
4
 
4
5
  module Linecook
5
6
  module Test
@@ -0,0 +1,71 @@
1
+ require 'test/unit'
2
+
3
+ if Object.const_defined?(:MiniTest)
4
+ ################################
5
+ # MiniTest shims (ruby 1.9)
6
+ ################################
7
+
8
+ class Test::Unit::TestCase
9
+ class << self
10
+ # Causes a test suite to be skipped. If a message is given, it will
11
+ # print and notify the user the test suite has been skipped.
12
+ def skip_test(msg=nil)
13
+ @@test_suites.delete(self)
14
+ puts "Skipping #{self}#{msg.empty? ? '' : ': ' + msg}"
15
+ end
16
+ end
17
+ end
18
+
19
+ # MiniTest renames method_name as name. For backwards compatibility it must
20
+ # be added back.
21
+ class MiniTest::Unit::TestCase
22
+ def method_name
23
+ __name__
24
+ end
25
+ end
26
+
27
+ else
28
+ ################################
29
+ # Test::Unit shims (< ruby 1.9)
30
+ ################################
31
+ # :stopdoc:
32
+ # Implementing skip_test in the original Test::Unit is considerably more
33
+ # tricky than in the Mini::Test Test::Unit.
34
+ class Test::Unit::TestCase
35
+ class << self
36
+ alias tap_original_test_case_inherited inherited
37
+
38
+ def inherited(child)
39
+ super
40
+ tap_original_test_case_inherited(child)
41
+ child.instance_variable_set(:@skip_messages, [])
42
+ child.instance_variable_set(:@run_test_suite, true)
43
+ end
44
+
45
+ # Causes a test suite to be skipped. If a message is given, it will
46
+ # print and notify the user the test suite has been skipped.
47
+ def skip_test(msg=nil)
48
+ @run_test_suite = false
49
+ @skip_messages << msg
50
+ end
51
+
52
+ alias :original_suite :suite
53
+
54
+ # Modifies the default suite method to skip the suit unless
55
+ # run_test_suite is true. If the test is skipped, the skip_messages
56
+ # will be printed along with the default 'Skipping <Test>' message.
57
+ def suite # :nodoc:
58
+ if @run_test_suite
59
+ original_suite
60
+ else
61
+ skip_message = @skip_messages.compact.join(', ')
62
+ puts "Skipping #{name}#{skip_message.empty? ? '' : ': ' + skip_message}"
63
+
64
+ # return an empty test suite of the appropriate name
65
+ Test::Unit::TestSuite.new(name)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ # :startdoc:
71
+ end
data/lib/linecook/test.rb CHANGED
@@ -18,39 +18,10 @@ module Linecook
18
18
  pattern.kind_of?(Regexp) ? pattern : /\A#{pattern}\z/
19
19
  end
20
20
 
21
- @skip_test_suite = false
22
21
  unless patterns.any? {|pattern| host =~ pattern }
23
22
  skip_test "not for host (#{host})"
24
23
  end
25
24
  end
26
-
27
- # Causes a test suite to be skipped. If a message is given, it will
28
- # print and notify the user the test suite has been skipped.
29
- def skip_test(msg=nil)
30
- @skip_test_suite = true
31
- skip_messages << msg
32
- end
33
-
34
- # Modifies the default suite method to skip the suit unless
35
- # run_test_suite is true. If the test is skipped, the skip_messages
36
- # will be printed along with the default 'Skipping <Test>' message.
37
- def suite # :nodoc:
38
- if (@skip_test_suite ||= false)
39
- skip_message = skip_messages.compact.join(', ')
40
- puts "Skipping #{name}#{skip_message.empty? ? '' : ': ' + skip_message}"
41
-
42
- # return an empty test suite of the appropriate name
43
- ::Test::Unit::TestSuite.new(name)
44
- else
45
- super
46
- end
47
- end
48
-
49
- protected
50
-
51
- def skip_messages # :nodoc:
52
- @skip_messages ||= []
53
- end
54
25
  end
55
26
 
56
27
  module ModuleMethods
@@ -5,7 +5,7 @@ module Linecook
5
5
  module_function
6
6
 
7
7
  def load_config(path)
8
- (path ? YAML.load_file(path) : nil) || {}
8
+ (path && File.exists?(path) ? YAML.load_file(path) : nil) || {}
9
9
  end
10
10
 
11
11
  def arrayify(obj)
@@ -1,6 +1,6 @@
1
1
  module Linecook
2
2
  MAJOR = 1
3
- MINOR = 1
3
+ MINOR = 2
4
4
  TINY = 0
5
5
 
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{TINY}"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linecook
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simon Chiang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-02 00:00:00 -06:00
18
+ date: 2011-05-23 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 49
29
+ hash: 59
30
30
  segments:
31
31
  - 0
32
- - 8
33
- - 7
34
- version: 0.8.7
32
+ - 9
33
+ - 0
34
+ version: 0.9.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -109,6 +109,7 @@ files:
109
109
  - lib/linecook/test/file_test.rb
110
110
  - lib/linecook/test/regexp_escape.rb
111
111
  - lib/linecook/test/shell_test.rb
112
+ - lib/linecook/test/shim.rb
112
113
  - lib/linecook/utils.rb
113
114
  - lib/linecook/version.rb
114
115
  - templates/Gemfile