jamie 0.1.0.alpha9 → 0.1.0.alpha10

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.
data/Rakefile CHANGED
@@ -6,8 +6,9 @@ desc "Run cane to check quality metrics"
6
6
  Cane::RakeTask.new do |cane|
7
7
  cane.abc_exclude = %w(
8
8
  Jamie::RakeTasks#define
9
+ Jamie::ThorTasks#define
9
10
  Jamie::Vagrant.define_vagrant_vm
10
- Jamie::CLI#console
11
+ Jamie::CLI#pry_prompts
11
12
  )
12
13
  cane.style_exclude = %w(
13
14
  lib/vendor/hash_recursive_merge.rb
data/lib/jamie/cli.rb CHANGED
@@ -9,6 +9,8 @@ module Jamie
9
9
  # The command line runner for Jamie.
10
10
  class CLI < Thor
11
11
 
12
+ include Thor::Actions
13
+
12
14
  # Constructs a new instance.
13
15
  def initialize(*args)
14
16
  super
@@ -38,26 +40,36 @@ module Jamie
38
40
  desc "console", "Jamie Console!"
39
41
  def console
40
42
  require 'pry'
41
- Pry.start(@config, :prompt => [
42
- proc { |target_self, nest_level, pry|
43
- [ "[#{pry.input_array.size}] ",
44
- "jc(#{Pry.view_clip(target_self.class)})",
45
- "#{":#{nest_level}" unless nest_level.zero?}> "
46
- ].join
47
- },
48
- proc { |target_self, nest_level, pry|
49
- [ "[#{pry.input_array.size}] ",
50
- "jc(#{Pry.view_clip(target_self.class)})",
51
- "#{":#{nest_level}" unless nest_level.zero?}* "
52
- ].join
53
- }
54
- ])
43
+ Pry.start(@config, :prompt => pry_prompts)
55
44
  rescue LoadError => e
56
45
  warn %{Make sure you have the pry gem installed. You can install it with:}
57
46
  warn %{`gem install pry` or including 'gem "pry"' in your Gemfile.}
58
47
  exit 1
59
48
  end
60
49
 
50
+ desc "init", "does the world"
51
+ def init
52
+ create_file ".jamie.yml", default_yaml
53
+ append_to_file("Rakefile", <<-RAKE.gsub(/ {8}/, '')) if init_rakefile?
54
+
55
+ begin
56
+ require 'jamie/rake_tasks'
57
+ Jamie::RakeTasks.new
58
+ rescue LoadError
59
+ puts ">>>>> Jamie gem not loaded, omitting tasks" unless ENV['CI']
60
+ end
61
+ RAKE
62
+ append_to_file("Thorfile", <<-THOR.gsub(/ {8}/, '')) if init_thorfile?
63
+
64
+ begin
65
+ require 'jamie/thor_tasks'
66
+ Jamie::ThorTasks.new
67
+ rescue LoadError
68
+ puts ">>>>> Jamie gem not loaded, omitting tasks" unless ENV['CI']
69
+ end
70
+ THOR
71
+ end
72
+
61
73
  private
62
74
 
63
75
  attr_reader :task
@@ -111,5 +123,95 @@ module Jamie
111
123
  help(task)
112
124
  exit 1
113
125
  end
126
+
127
+ def pry_prompts
128
+ [ proc { |target_self, nest_level, pry|
129
+ [ "[#{pry.input_array.size}] ",
130
+ "jc(#{Pry.view_clip(target_self.class)})",
131
+ "#{":#{nest_level}" unless nest_level.zero?}> "
132
+ ].join
133
+ },
134
+ proc { |target_self, nest_level, pry|
135
+ [ "[#{pry.input_array.size}] ",
136
+ "jc(#{Pry.view_clip(target_self.class)})",
137
+ "#{":#{nest_level}" unless nest_level.zero?}* "
138
+ ].join
139
+ }
140
+ ]
141
+ end
142
+
143
+ def default_yaml
144
+ url_base = "https://opscode-vm.s3.amazonaws.com/vagrant/boxes"
145
+ platforms = [
146
+ { :n => 'ubuntu', :vers => %w(10.04 12.04), :rl => "recipe[apt]" },
147
+ { :n => 'centos', :vers => %w(5.8 6.3), :rl => "recipe[yum::epel]" }
148
+ ]
149
+ platforms = platforms.map do |p|
150
+ p[:vers].map do |v|
151
+ { 'name' => "#{p[:n]}-#{v}",
152
+ 'driver_config' => {
153
+ 'box' => "opscode-#{p[:n]}-#{v}",
154
+ 'box_url' => "#{url_base}/opscode-#{p[:n]}-#{v}.box"
155
+ },
156
+ 'run_list' => Array(p[:rl])
157
+ }
158
+ end
159
+ end.flatten
160
+ cookbook_name = MetadataChopper.extract('metadata.rb').first
161
+ run_list = cookbook_name ? "recipe[#{cookbook_name}]" : nil
162
+ attributes = cookbook_name ? { cookbook_name => nil } : nil
163
+
164
+ { 'default_driver' => 'vagrant',
165
+ 'platforms' => platforms,
166
+ 'suites' => [
167
+ { 'name' => 'standard',
168
+ 'run_list' => Array(run_list),
169
+ 'attributes' => attributes
170
+ }
171
+ ]
172
+ }.to_yaml
173
+ end
174
+
175
+ def init_rakefile?
176
+ File.exists?("Rakefile") &&
177
+ IO.readlines("Rakefile").grep(%r{require 'jamie/rake_tasks'}).empty?
178
+ end
179
+
180
+ def init_thorfile?
181
+ File.exists?("Thorfile") &&
182
+ IO.readlines("Thorfile").grep(%r{require 'jamie/thor_tasks'}).empty?
183
+ end
184
+
185
+ # A rather insane and questionable class to quickly consume a metadata.rb
186
+ # file and return the cookbook name and version attributes.
187
+ #
188
+ # @see https://twitter.com/fnichol/status/281650077901144064
189
+ # @see https://gist.github.com/4343327
190
+ class MetadataChopper < Hash
191
+
192
+ # Return an Array containing the cookbook name and version attributes,
193
+ # or nil values if they could not be parsed.
194
+ #
195
+ # @param metadata_file [String] path to a metadata.rb file
196
+ # @return [Array<String>] array containing the cookbook name and version
197
+ # attributes or nil values if they could not be determined
198
+ def self.extract(metadata_file)
199
+ mc = new(File.expand_path(metadata_file))
200
+ [ mc[:name], mc[:version] ]
201
+ end
202
+
203
+ # Creates a new instances and loads in the contents of the metdata.rb
204
+ # file. If you value your life, you may want to avoid reading the
205
+ # implementation.
206
+ #
207
+ # @param metadata_file [String] path to a metadata.rb file
208
+ def initialize(metadata_file)
209
+ eval(IO.read(metadata_file), nil, metadata_file)
210
+ end
211
+
212
+ def method_missing(meth, *args, &block)
213
+ self[meth] = args.first
214
+ end
215
+ end
114
216
  end
115
217
  end
@@ -1,6 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- require 'rake'
4
3
  require 'rake/tasklib'
5
4
 
6
5
  require 'jamie'
@@ -10,17 +9,10 @@ module Jamie
10
9
  # Jamie Rake task generator.
11
10
  class RakeTasks < ::Rake::TaskLib
12
11
 
13
- # @return [String] prefix name of all Jamie tasks
14
- attr_accessor :name
15
-
16
- # @return [Jamie::Config] a Jamie config object
17
- attr_accessor :config
18
-
19
12
  # Creates Jamie Rake tasks and allows the callee to configure it.
20
13
  #
21
14
  # @yield [self] gives itself to the block
22
- def initialize(name = :jamie)
23
- @name = name
15
+ def initialize
24
16
  @config = Jamie::Config.new
25
17
  yield self if block_given?
26
18
  define
@@ -28,28 +20,18 @@ module Jamie
28
20
 
29
21
  private
30
22
 
23
+ attr_reader :config
24
+
31
25
  def define
32
- namespace name do
26
+ namespace "jamie" do
33
27
  config.instances.each do |instance|
34
28
  desc "Run #{instance.name} test instance"
35
- task instance.name do
36
- instance.test
37
- end
38
-
39
- namespace instance.name do
40
- desc "Destroy #{instance.name} test instance"
41
- task :destroy do
42
- instance.destroy
43
- end
44
- end
29
+ task instance.name { instance.test }
45
30
  end
46
31
 
47
- desc "Destroy all instances"
48
- task :destroy => config.instances.map { |i| "#{i.name}:destroy" }
32
+ desc "Run all test instances"
33
+ task "all" => config.instances.map { |i| i.name }
49
34
  end
50
-
51
- desc "Run Jamie integration"
52
- task name => config.instances.map { |i| "#{name}:#{i.name}" }
53
35
  end
54
36
  end
55
37
  end
@@ -0,0 +1,42 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'thor'
4
+
5
+ require 'jamie'
6
+
7
+ module Jamie
8
+
9
+ # Jamie Thor task generator.
10
+ class ThorTasks < Thor
11
+
12
+ namespace :jamie
13
+
14
+ # Creates Jamie Thor tasks and allows the callee to configure it.
15
+ #
16
+ # @yield [self] gives itself to the block
17
+ def initialize(*args)
18
+ super
19
+ @config = Jamie::Config.new
20
+ yield self if block_given?
21
+ define
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :config
27
+
28
+ def define
29
+ config.instances.each do |instance|
30
+ self.class.desc instance.name, "Run #{instance.name} test instance"
31
+ self.class.send(:define_method, instance.name.gsub(/-/, '_')) do
32
+ instance.test
33
+ end
34
+ end
35
+
36
+ self.class.desc "all", "Run all test instances"
37
+ self.class.send(:define_method, :all) do
38
+ config.instances.each { |i| invoke i.name.gsub(/-/, '_') }
39
+ end
40
+ end
41
+ end
42
+ end
data/lib/jamie/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Jamie
4
4
 
5
- VERSION = "0.1.0.alpha9"
5
+ VERSION = "0.1.0.alpha10"
6
6
  end
data/lib/jamie.rb CHANGED
@@ -567,7 +567,7 @@ module Jamie
567
567
  def self.for_plugin(plugin, config)
568
568
  require "jamie/driver/#{plugin}"
569
569
 
570
- klass = self.const_get(plugin.capitalize)
570
+ klass = self.const_get(plugin.split('_').map { |w| w.capitalize }.join)
571
571
  klass.new(config)
572
572
  end
573
573
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jamie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha9
4
+ version: 0.1.0.alpha10
5
5
  prerelease: 6
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: 2012-12-18 00:00:00.000000000 Z
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -176,6 +176,7 @@ files:
176
176
  - lib/jamie/cli.rb
177
177
  - lib/jamie/driver/vagrant.rb
178
178
  - lib/jamie/rake_tasks.rb
179
+ - lib/jamie/thor_tasks.rb
179
180
  - lib/jamie/vagrant.rb
180
181
  - lib/jamie/version.rb
181
182
  - lib/vendor/hash_recursive_merge.rb
@@ -193,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
194
  version: '0'
194
195
  segments:
195
196
  - 0
196
- hash: -3537010149917719501
197
+ hash: -2703897808441646457
197
198
  required_rubygems_version: !ruby/object:Gem::Requirement
198
199
  none: false
199
200
  requirements: