milkshake 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -8,31 +8,17 @@ module Milkshake
8
8
  override_app_path! path
9
9
  assert_new_app_path!
10
10
 
11
- system(%{rails "#{self.options.app}" > /dev/null})
11
+ system(%{rails _#{Milkshake::RAILS_VERSION}_ "#{self.options.app}" > /dev/null})
12
12
  good_say('Rails app successfully created!')
13
13
 
14
- goto_rails do
15
- if File.file?('config/locales/en.yml')
16
- File.unlink('config/locales/en.yml')
17
- end
18
- if File.file?('public/index.html')
19
- File.unlink('public/index.html')
20
- end
21
- if File.file?('public/images/rails.png')
22
- File.unlink('public/images/rails.png')
23
- end
24
- if File.file?('public/javascripts/controls.js')
25
- File.unlink('public/javascripts/controls.js')
26
- end
27
- if File.file?('public/javascripts/dragdrop.js')
28
- File.unlink('public/javascripts/dragdrop.js')
29
- end
30
- if File.file?('public/javascripts/effects.js')
31
- File.unlink('public/javascripts/effects.js')
32
- end
33
- if File.file?('public/javascripts/prototype.js')
34
- File.unlink('public/javascripts/prototype.js')
35
- end
14
+ goto_rails do |rails_root|
15
+ safe_rm(rails_root + 'config/locales/en.yml')
16
+ safe_rm(rails_root + 'public/index.html')
17
+ safe_rm(rails_root + 'public/images/rails.png')
18
+ safe_rm(rails_root + 'public/javascripts/controls.js')
19
+ safe_rm(rails_root + 'public/javascripts/dragdrop.js')
20
+ safe_rm(rails_root + 'public/javascripts/effects.js')
21
+ safe_rm(rails_root + 'public/javascripts/prototype.js')
36
22
 
37
23
  Milkshake::Template.evaluate('routes.rb'
38
24
  ).write_to('config/routes.rb')
@@ -60,26 +46,16 @@ module Milkshake
60
46
  def install_gem!(name)
61
47
  assert_valid_gem_name! name
62
48
 
63
- goto_rails do
49
+ goto_rails do |rails_root|
64
50
 
65
51
  Milkshake::Template.evaluate('jeweler.rake',
66
- :name => name,
67
- :author => ask_unless_given(
68
- 'Author', self.options.author, self.class.default_author),
69
- :email => ask_unless_given(
70
- 'Email', self.options.email, self.class.default_email),
71
- :summary => ask_unless_given(
72
- 'Summary', self.options.summary, 'FIX_ME_SUMMARY'),
73
- :description => ask_unless_given(
74
- 'Description', self.options.description, 'FIX_ME_DESCRIPTION'),
75
- :website => ask_unless_given(
76
- 'Website', self.options.website, 'FIX_ME_WEBSITE')
52
+ gem_options(name)
77
53
  ).write_to('lib/tasks/jeweler.rake')
78
54
 
79
55
  FileUtils.mkdir_p('rails/initializers')
80
56
  FileUtils.touch('rails/init.rb')
81
- FileUtils.rm_rf('app/controllers/application_controller.rb') rescue nil
82
- FileUtils.rm_rf('app/helpers/application_helper.rb') rescue nil
57
+ safe_rm(rails_root + 'app/controllers/application_controller.rb')
58
+ safe_rm(rails_root + 'app/helpers/application_helper.rb')
83
59
 
84
60
  if self.options.git or shell.yes?('Initialize git? [yN]:')
85
61
  system(%{ git init > /dev/null })
@@ -97,18 +73,18 @@ module Milkshake
97
73
 
98
74
  def install_host!
99
75
  goto_rails do |rails_root|
100
- (rails_root + 'README').unlink rescue nil
101
- (rails_root + 'Rakefile').unlink rescue nil
102
- (rails_root + 'app').rmtree rescue nil
103
- (rails_root + 'config/locales').rmtree rescue nil
104
- (rails_root + 'db/seeds.rb').unlink rescue nil
105
- (rails_root + 'doc').rmtree rescue nil
106
- (rails_root + 'lib').rmtree rescue nil
107
- (rails_root + 'public/images').rmtree rescue nil
108
- (rails_root + 'public/javascripts').rmtree rescue nil
109
- (rails_root + 'public/stylesheets').rmtree rescue nil
110
- (rails_root + 'test').rmtree rescue nil
111
- (rails_root + 'vendor').rmtree rescue nil
76
+ safe_rm(rails_root + 'README')
77
+ safe_rm(rails_root + 'Rakefile')
78
+ safe_rm(rails_root + 'app')
79
+ safe_rm(rails_root + 'config/locales')
80
+ safe_rm(rails_root + 'db/seeds.rb')
81
+ safe_rm(rails_root + 'doc')
82
+ safe_rm(rails_root + 'lib')
83
+ safe_rm(rails_root + 'public/images')
84
+ safe_rm(rails_root + 'public/javascripts')
85
+ safe_rm(rails_root + 'public/stylesheets')
86
+ safe_rm(rails_root + 'test')
87
+ safe_rm(rails_root + 'vendor')
112
88
  end
113
89
 
114
90
  good_say('Rails app successfully stripped!')
@@ -185,32 +161,32 @@ module Milkshake
185
161
 
186
162
  goto_rails do |rails_path|
187
163
 
188
- (rails_path + 'db').rmtree
164
+ safe_rm(rails_path + 'db')
189
165
  make_symlink!(
190
166
  rails_path + 'db',
191
167
  shared_path + 'private')
192
168
 
193
- (rails_path + 'log').rmtree
169
+ safe_rm(rails_path + 'log')
194
170
  make_symlink!(
195
171
  rails_path + 'log',
196
172
  shared_path + 'log')
197
173
 
198
- (rails_path + 'public/system').rmtree if File.exist?('public/system')
174
+ safe_rm(rails_path + 'public/system')
199
175
  make_symlink!(
200
176
  rails_path + 'public/system',
201
177
  shared_path + 'public')
202
178
 
203
- (rails_path + 'config/settings').rmtree if File.exist?('config/settings')
179
+ safe_rm(rails_path + 'config/settings')
204
180
  make_symlink!(
205
181
  rails_path + 'config/settings',
206
182
  shared_path + 'settings')
207
183
 
208
- (rails_path + 'config/milkshake.yml').unlink if File.exist?('config/milkshake.yml')
184
+ safe_rm(rails_path + 'config/milkshake.yml')
209
185
  make_symlink!(
210
186
  rails_path + 'config/milkshake.yml',
211
187
  shared_path + 'settings/milkshake.yml')
212
188
 
213
- (rails_path + 'config/database.yml').unlink if File.exist?('config/database.yml')
189
+ safe_rm(rails_path + 'config/database.yml')
214
190
  make_symlink!(
215
191
  rails_path + 'config/database.yml',
216
192
  shared_path + 'settings/database.yml')
@@ -218,6 +194,30 @@ module Milkshake
218
194
  end
219
195
  end
220
196
 
197
+ private
198
+
199
+ def gem_options(name)
200
+ {
201
+ :name =>
202
+ name,
203
+
204
+ :author =>
205
+ ask_unless_given('Author', self.options.author, self.class.default_author),
206
+
207
+ :email =>
208
+ ask_unless_given('Email', self.options.email, self.class.default_email),
209
+
210
+ :summary =>
211
+ ask_unless_given('Summary', self.options.summary, 'FIX_ME_SUMMARY'),
212
+
213
+ :description =>
214
+ ask_unless_given('Description', self.options.description, 'FIX_ME_DESCRIPTION'),
215
+
216
+ :website =>
217
+ ask_unless_given('Website', self.options.website, 'FIX_ME_WEBSITE')
218
+ }
219
+ end
220
+
221
221
  end
222
222
  end
223
223
  end
@@ -108,6 +108,15 @@ module Milkshake
108
108
  make_symlink! old_path, new_path
109
109
  end
110
110
 
111
+ def safe_rm(path)
112
+ path = Pathname.new(path) unless Pathname === path
113
+ if path.file? or path.symlink?
114
+ path.unlink
115
+ elsif path.directory?
116
+ path.rmtree
117
+ end
118
+ end
119
+
111
120
  end
112
121
  end
113
122
  end
@@ -7,7 +7,7 @@ module Milkshake
7
7
  def initialize(path)
8
8
  @path = path
9
9
  begin
10
- File.open(@path, 'r') { |f| @entries = Marshal.load(f.read) }
10
+ File.open(@path, 'r') { |file| @entries = Marshal.load(file.read) }
11
11
  raise 'wrong type' unless Hash === @entries
12
12
  rescue
13
13
  @entries = {}
@@ -16,10 +16,11 @@ module Milkshake
16
16
  end
17
17
 
18
18
  def key(name)
19
- if @entries.key?(name.to_s)
20
- @entries[name.to_s]
19
+ name = name.to_s
20
+ if @entries.key?(name)
21
+ @entries[name]
21
22
  elsif block_given?
22
- @entries[name.to_s] = yield
23
+ @entries[name] = yield
23
24
  else
24
25
  nil
25
26
  end
@@ -43,7 +44,7 @@ module Milkshake
43
44
  end
44
45
 
45
46
  def persist!
46
- File.open(@path, 'w+') { |f| f.write Marshal.dump(@entries) }
47
+ File.open(@path, 'w+') { |file| file.write Marshal.dump(@entries) }
47
48
  end
48
49
 
49
50
  end
@@ -14,12 +14,12 @@ module Milkshake
14
14
  end
15
15
 
16
16
  def initialize(gems)
17
- specs = gems.collect do |k,r|
18
- find_gemspec(k, r)
17
+ specs = gems.collect do |name,options|
18
+ find_gemspec(name,options)
19
19
  end.compact
20
20
 
21
21
  @names = specs.collect { |spec| spec.name }
22
- @specs = specs.inject({}) { |h, spec| h[spec.name] = spec ; h }
22
+ @specs = specs.inject({}) { |memo, spec| memo[spec.name] = spec ; memo }
23
23
  @gems = gems
24
24
  end
25
25
 
@@ -56,8 +56,8 @@ module Milkshake
56
56
  raise "Failed to resolve dependency: #{name} #{options.inspect}"
57
57
  end
58
58
 
59
- specs.sort! do |a,b|
60
- b.version <=> a.version
59
+ specs.sort! do |left,right|
60
+ right.version <=> left.version
61
61
  end
62
62
 
63
63
  gemspec = specs.first
@@ -36,16 +36,16 @@ module Milkshake
36
36
  resolver ||= DependencyResolver.load_for(@options['gems'])
37
37
  specs = resolver.specs
38
38
  @gemspecs = specs
39
- specs.inject({}) { |s, (name, spec)| s[name] = spec.version.to_s ; s }
39
+ specs.inject({}) { |memo, (name, spec)| memo[name] = spec.version.to_s ; memo }
40
40
  end
41
41
 
42
- @gemspecs ||= @gemspec_versions.inject({}) do |s, (name, version)|
42
+ @gemspecs ||= @gemspec_versions.inject({}) do |memo, (name, version)|
43
43
  specs = index.search(Gem::Dependency.new(name, version))
44
- specs.sort! do |a,b|
45
- b.version <=> a.version
44
+ specs.sort! do |left,right|
45
+ right.version <=> left.version
46
46
  end
47
- s[name] = specs.first
48
- s
47
+ memo[name] = specs.first
48
+ memo
49
49
  end
50
50
 
51
51
  @order = @cache.key('environment.gems.order') do
@@ -67,8 +67,8 @@ module Milkshake
67
67
  end
68
68
 
69
69
  def gem_dependencies
70
- @order.inject([]) do |g, name|
71
- g << Rails::GemDependency.new(name, @gems[name])
70
+ @order.inject([]) do |deps, name|
71
+ deps << Rails::GemDependency.new(name, @gems[name])
72
72
  end
73
73
  end
74
74
 
@@ -14,13 +14,13 @@ module Milkshake
14
14
  # for passenger
15
15
  def extend_rails!
16
16
  Object.const_set('Rails', Module.new)
17
- r = Object.const_get('Rails')
18
- def r.singleton_method_added(m)
19
- if (m.to_s == 'boot!') and !@injected_milkshake
17
+ rails_mod = Object.const_get('Rails')
18
+ def rails_mod.singleton_method_added(meth)
19
+ if (meth.to_s == 'boot!') and !@injected_milkshake
20
20
  @injected_milkshake = true
21
- k = (class << self ; self ; end)
22
- k.send :alias_method, "milkshakeless_#{m}", m
23
- k.send :define_method, m do
21
+ klass = (class << self ; self ; end)
22
+ klass.send :alias_method, "milkshakeless_#{meth}", meth
23
+ klass.send :define_method, meth do
24
24
  milkshakeless_boot!
25
25
  Milkshake.load!
26
26
  Milkshake.extender.extend_railties!
@@ -15,7 +15,7 @@ module Milkshake
15
15
  def link!
16
16
  link_only_once do
17
17
  if validator.relink?
18
- @current_snapshot = Snapshots.dump
18
+ # @current_snapshot = Snapshots.dump
19
19
 
20
20
  run_migrations!
21
21
 
@@ -24,8 +24,9 @@ module Milkshake
24
24
  self.environment.gemspecs.each do |gemspec|
25
25
  paths.concat Dir.glob(File.join(gemspec.full_gem_path, *relative_path))
26
26
  end
27
- paths.concat Dir.glob(File.join(Rails.root, 'rails/init.rb'))
28
- paths.concat Dir.glob(File.join(Rails.root, *relative_path))
27
+ rails_root = Rails.root
28
+ paths.concat Dir.glob(File.join(rails_root, 'rails/init.rb'))
29
+ paths.concat Dir.glob(File.join(rails_root, *relative_path))
29
30
  paths
30
31
  end
31
32
  end
@@ -4,9 +4,9 @@ module Milkshake
4
4
  module Configuration
5
5
 
6
6
  def self.included(base)
7
- %w( default_gems default_i18n default_load_paths ).each do |m|
8
- base.send :alias_method, "#{m}_without_milkshake", m
9
- base.send :alias_method, m, "#{m}_with_milkshake"
7
+ %w( default_gems default_i18n default_load_paths ).each do |meth|
8
+ base.send :alias_method, "#{meth}_without_milkshake", meth
9
+ base.send :alias_method, meth, "#{meth}_with_milkshake"
10
10
  end
11
11
  end
12
12
 
@@ -27,6 +27,13 @@ module Milkshake
27
27
 
28
28
  # inject fallback application controller
29
29
  def default_load_paths_with_milkshake
30
+ Milkshake.environment.gemspecs.each do |gemspec|
31
+ app_path = File.join(gemspec.full_gem_path, 'app', 'controllers', 'application_controller.rb')
32
+ if File.file?(app_path)
33
+ return default_load_paths_without_milkshake
34
+ end
35
+ end
36
+
30
37
  path = File.expand_path(File.join(File.dirname(__FILE__), *%w( .. rails_fallbacks )))
31
38
  default_load_paths_without_milkshake.push(path)
32
39
  end
@@ -4,9 +4,9 @@ module Milkshake
4
4
  module Initializer
5
5
 
6
6
  def self.included(base)
7
- %w( require_frameworks check_for_unbuilt_gems load_application_initializers process ).each do |m|
8
- base.send :alias_method, "#{m}_without_milkshake", m
9
- base.send :alias_method, m, "#{m}_with_milkshake"
7
+ %w( require_frameworks check_for_unbuilt_gems load_application_initializers process ).each do |meth|
8
+ base.send :alias_method, "#{meth}_without_milkshake", meth
9
+ base.send :alias_method, meth, "#{meth}_with_milkshake"
10
10
  end
11
11
  end
12
12
 
@@ -30,7 +30,7 @@ module Milkshake
30
30
 
31
31
  def process_with_milkshake
32
32
  process_without_milkshake
33
- rescue Exception => e
33
+ rescue Exception => exception
34
34
  begin
35
35
  Milkshake.cache.restore!
36
36
  Milkshake.environment.reload!
@@ -38,9 +38,10 @@ module Milkshake
38
38
  Snapshots.load(Milkshake.linker.current_snapshot)
39
39
  end
40
40
  rescue Exception
41
+ nil
41
42
  end
42
43
 
43
- raise e
44
+ raise exception
44
45
  end
45
46
 
46
47
  end
@@ -30,7 +30,7 @@ module Milkshake
30
30
 
31
31
  def evaluate(context={})
32
32
  result = @template.dup
33
- result.gsub!(/\{\{([a-zA-Z0-9_.-]+)\}\}/) do |m|
33
+ result.gsub!(/\{\{([a-zA-Z0-9_.-]+)\}\}/) do |match|
34
34
  (context[$1] || context[$1.to_sym]).to_s
35
35
  end
36
36
  result.extend SourceFile
@@ -40,7 +40,7 @@ module Milkshake
40
40
  module SourceFile
41
41
  def write_to(path)
42
42
  FileUtils.mkdir_p(File.dirname(path))
43
- File.open(path, 'w+') { |f| f.write self }
43
+ File.open(path, 'w+') { |file| file.write self }
44
44
  self
45
45
  end
46
46
  end
data/lib/milkshake.rb CHANGED
@@ -3,6 +3,8 @@ require 'fileutils'
3
3
 
4
4
  module Milkshake
5
5
 
6
+ RAILS_VERSION = "2.3.4"
7
+
6
8
  autoload :DependencyResolver, 'milkshake/dependency_resolver'
7
9
  autoload :Environment, 'milkshake/environment'
8
10
  autoload :Validator, 'milkshake/validator'
data/milkshake.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{milkshake}
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Simon Menke"]
12
- s.date = %q{2009-11-17}
12
+ s.date = %q{2010-01-21}
13
13
  s.default_executable = %q{milkshake}
14
14
  s.description = %q{Compose rails applications using several smaller rails applications}
15
15
  s.email = %q{simon@mrhenry.be}
@@ -27,58 +27,32 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "bin/milkshake",
29
29
  "lib/milkshake.rb",
30
- "lib/milkshake.rb",
31
- "lib/milkshake/app.rb",
32
30
  "lib/milkshake/app.rb",
33
31
  "lib/milkshake/app/actions.rb",
34
- "lib/milkshake/app/actions.rb",
35
- "lib/milkshake/app/defaults.rb",
36
32
  "lib/milkshake/app/defaults.rb",
37
33
  "lib/milkshake/app/helpers.rb",
38
- "lib/milkshake/app/helpers.rb",
39
- "lib/milkshake/automagic.rb",
40
34
  "lib/milkshake/automagic.rb",
41
35
  "lib/milkshake/cache.rb",
42
- "lib/milkshake/cache.rb",
43
36
  "lib/milkshake/dependency_resolver.rb",
44
- "lib/milkshake/dependency_resolver.rb",
45
- "lib/milkshake/environment.rb",
46
37
  "lib/milkshake/environment.rb",
47
38
  "lib/milkshake/extender.rb",
48
- "lib/milkshake/extender.rb",
49
39
  "lib/milkshake/linker.rb",
50
- "lib/milkshake/linker.rb",
51
- "lib/milkshake/loader.rb",
52
40
  "lib/milkshake/loader.rb",
53
41
  "lib/milkshake/rails_extentions/boot.rb",
54
- "lib/milkshake/rails_extentions/boot.rb",
55
42
  "lib/milkshake/rails_extentions/configuration.rb",
56
- "lib/milkshake/rails_extentions/configuration.rb",
57
- "lib/milkshake/rails_extentions/initializer.rb",
58
43
  "lib/milkshake/rails_extentions/initializer.rb",
59
44
  "lib/milkshake/rails_extentions/migrations.rb",
60
- "lib/milkshake/rails_extentions/migrations.rb",
61
- "lib/milkshake/rails_fallbacks/application_controller.rb",
62
45
  "lib/milkshake/rails_fallbacks/application_controller.rb",
63
46
  "lib/milkshake/rubygems_extentions/specification.rb",
64
- "lib/milkshake/rubygems_extentions/specification.rb",
65
- "lib/milkshake/template.rb",
66
47
  "lib/milkshake/template.rb",
67
48
  "lib/milkshake/validator.rb",
68
- "lib/milkshake/validator.rb",
69
49
  "milkshake.gemspec",
70
50
  "templates/gitignore",
71
- "templates/gitignore",
72
- "templates/gitignore_for_data",
73
51
  "templates/gitignore_for_data",
74
52
  "templates/jeweler.rake",
75
- "templates/jeweler.rake",
76
53
  "templates/milkshake.yml",
77
- "templates/milkshake.yml",
78
- "templates/preinitializer.rb",
79
54
  "templates/preinitializer.rb",
80
55
  "templates/routes.rb",
81
- "templates/routes.rb",
82
56
  "test/milkshake_test.rb",
83
57
  "test/test_helper.rb"
84
58
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milkshake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Menke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-17 00:00:00 +01:00
12
+ date: 2010-01-21 00:00:00 +01:00
13
13
  default_executable: milkshake
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency