generator_extensions 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -67,6 +67,19 @@ Well, then just call this in your manifest:
67
67
 
68
68
  m.add_to_routes @route_text
69
69
 
70
+ In 0.3.0, I've also added a similar function for the initializer in
71
+ <tt>config/environment.rb</tt>, for those things (like
72
+ <tt>config.gem</tt>) that don't go in a file in <tt>initializers/</tt>
73
+
74
+ m.add_to_initializers "config.gem 'foo'\nconfig.gem 'bar'"
75
+
76
+ They're both implemented using a generic <tt>add_to_file()</tt>, which
77
+ you use like this:
78
+
79
+ m.add_to_file "filename", "sentinel", "text to insert"
80
+
81
+ The sentinel is the text immediately preceding the insert.
82
+
70
83
  One problem with mirroring a directory tree is that at the moment
71
84
  there is no way to distinguish between existing directories (say, the
72
85
  ones rails sets up) and any new ones you've implicitly created by
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{generator_extensions}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcel Levy"]
12
- s.date = %q{2009-12-18}
12
+ s.date = %q{2009-12-22}
13
13
  s.description = %q{Functions that make it easier to write a Rails generator.}
14
14
  s.email = %q{heymarcel@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -33,11 +33,24 @@ module Rails
33
33
  include RailsGeneratorExtensions
34
34
 
35
35
  def add_to_routes(text)
36
+ add_to_file('config/routes.rb',
37
+ 'ActionController::Routing::Routes.draw do |map|',
38
+ text
39
+ )
40
+ end
41
+
42
+ def add_to_initializer(text)
43
+ add_to_file('config/environment.rb',
44
+ 'Rails::Initializer.run do |config|',
45
+ text)
46
+ end
47
+
48
+ def add_to_file(file, sentinel, text)
36
49
  first_line = text.split("\n")[0]
37
- logger.routes "#{first_line} ..."
50
+ m = /:in `([^']+)'$/.match(caller.first)
51
+ logger.send(m[1].to_sym, first_line) if m
38
52
  unless options[:pretend]
39
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
40
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
53
+ gsub_file file, /(#{Regexp.escape(sentinel)})/mi do |match|
41
54
  "#{match}\n#{text}\n"
42
55
  end
43
56
  end
@@ -49,10 +62,19 @@ module Rails
49
62
  include RailsGeneratorExtensions
50
63
 
51
64
  def add_to_routes(text)
65
+ add_to_file('config/routes.rb', nil, text)
66
+ end
67
+
68
+ def add_to_initializer(text)
69
+ add_to_file('config/environment.rb', nil, text)
70
+ end
71
+
72
+ def add_to_file(file, sentinel, text)
52
73
  first_line = text.split("\n")[0]
53
- logger.routes "#{first_line} ..."
54
- gsub_file 'config/routes.rb', /(#{Regexp.escape(text)})/mi, ''
74
+ logger.removing first_line
75
+ gsub_file file, /(#{Regexp.escape(text)}\n)/mi, ''
55
76
  end
77
+
56
78
  end
57
79
 
58
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generator_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcel Levy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-18 00:00:00 -08:00
12
+ date: 2009-12-22 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15