refinerycms-generators 0.9.9.4 → 0.9.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gemspec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- version = '0.9.9.4'
2
+ version = '0.9.9.5'
3
3
  raise "Could not get version so gemspec can not be built" if version.nil?
4
4
  files = Dir.glob("**/*").flatten.reject do |file|
5
5
  file =~ /\.gem$/
@@ -86,24 +86,11 @@ class RefineryEngineGenerator < Rails::Generators::NamedBase
86
86
  l =~ %r{refinerycms-#{plural_name}}
87
87
  }.join("\n"))
88
88
 
89
- migration_files = Dir.glob(File.expand_path('../templates/db/migrate/*.rb', __FILE__)).sort.collect{|m|
90
- m.gsub('plural_name', plural_name).gsub('singular_name', singular_name).split(File::SEPARATOR).last.split('_')[1..-1].join('_')
91
- }
92
- if (migration_paths = Dir[Rails.root.join('db', 'migrate', "*#{migration_files.join(',')}")]).any?
93
- puts ""
94
- puts "I found #{'a ' unless migration_paths.many?}migration#{'s' if migration_paths.many?} at:"
95
- puts migration_paths.join("\n")
96
- puts ""
97
- puts "Please ensure that you roll back these migrations if you used them (using rake db:rollback) and then run:"
98
- puts "------------------------"
99
- puts "rm #{migration_paths.join("\n rm ")}"
100
- puts "rm #{Rails.root.join('db', 'seeds', "#{plural_name}.rb")}"
101
- puts "------------------------"
102
- puts "This will ensure that nothing gets left behind from this engine in your database."
103
- puts "Note - be careful about rolling back if you have any migrations created after this one."
104
- puts "This is because Rails rolls back only the last migration used each time you invoke rake db:rollback"
105
- puts ""
106
- end
89
+ ::Refinery::Generators::Migrations.revoke({
90
+ :pattern => File.expand_path('../templates/db/migrate/*.rb', __FILE__),
91
+ :plural_name => plural_name,
92
+ :singular_name => singular_name
93
+ })
107
94
  end
108
95
  else
109
96
  puts "You must specify at least one field. For help: rails generate refinery_engine"
@@ -1,8 +1,8 @@
1
1
  class <%= class_name %> < ActiveRecord::Base
2
+ <% if (string_attributes = attributes.map{ |attribute| attribute.name.to_sym if attribute.type.to_s =~ /string|text/ }.compact.uniq).any? %>
3
+ acts_as_indexed :fields => <%= string_attributes.inspect %>
2
4
 
3
- acts_as_indexed :fields => [:<%= attributes.collect{ |attribute| attribute.name if attribute.type.to_s =~ /string|text/ }.compact.uniq.join(", :") %>]
4
- <% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>
5
- validates :<%= title.name %>, :presence => true, :uniqueness => true
5
+ validates <%= string_attributes.first.inspect %>, :presence => true, :uniqueness => true
6
6
  <% else %>
7
7
  # def title was created automatically because you didn't specify a string field
8
8
  # when you ran the refinery_engine generator. Love, Refinery CMS.
@@ -0,0 +1,69 @@
1
+ require File.expand_path('../../generators', __FILE__)
2
+ require 'rails/generators'
3
+ require 'rails/generators/named_base'
4
+ require 'rails/generators/migration'
5
+
6
+ module Refinery
7
+ module Generators
8
+ # The core engine installer streamlines the installation of custom generated
9
+ # engines. It takes the migrations and seeds in your engine and moves them
10
+ # into the rails app db directory, ready to migrate.
11
+ class EngineInstaller < Rails::Generators::Base
12
+
13
+ include Rails::Generators::Migration
14
+
15
+ attr_accessor :silence_puts
16
+ def silence_puts
17
+ !!@silence_puts
18
+ end
19
+
20
+ class << self
21
+
22
+ def engine_name(name = nil)
23
+ @engine_name = name.to_s unless name.nil?
24
+ @engine_name
25
+ end
26
+
27
+ def source_root(root = nil)
28
+ Pathname.new(super.to_s)
29
+ end
30
+
31
+ # Implement the required interface for Rails::Generators::Migration.
32
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
33
+ # can be removed once this issue is fixed:
34
+ # # https://rails.lighthouseapp.com/projects/8994/tickets/3820-make-railsgeneratorsmigrationnext_migration_number-method-a-class-method-so-it-possible-to-use-it-in-custom-generators
35
+ def next_migration_number(dirname)
36
+ ::ActiveRecord::Generators::Base.next_migration_number(dirname)
37
+ end
38
+ end
39
+
40
+ def generate
41
+ Pathname.glob(self.class.source_root.join('db', '**', '*.rb')).sort.each do |path|
42
+ case path.to_s
43
+ when %r{.*/migrate/.*}
44
+ # unless the migration has already been generated.
45
+ migration_name = "#{path.split.last.to_s.split(/^\d+_/).last}"
46
+ unless Dir[Rails.root.join('db', 'migrate', "*#{migration_name}")].any?
47
+ migration_template path, Rails.root.join('db', 'migrate', migration_name)
48
+ else
49
+ puts "You already have a migration called #{migration_name.split('.rb').first}" unless self.silence_puts || self.behavior == :revoke
50
+ end
51
+ when %r{.*/seeds/.*}
52
+ template path, Rails.root.join('db', 'seeds', path.to_s.split('/seeds/').last)
53
+ end
54
+ end
55
+
56
+ if !self.silence_puts && self.behavior != :revoke
57
+ puts "------------------------"
58
+ puts "Now run:"
59
+ puts "rake db:migrate"
60
+ puts "------------------------"
61
+ elsif self.behavior == :revoke
62
+ ::Refinery::Generators::Migrations.revoke({
63
+ :pattern => self.class.source_root.join('db', 'migrate', '*.rb')
64
+ })
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,35 @@
1
+ module Refinery
2
+ module Generators
3
+ module Migrations
4
+ class << self
5
+ def revoke(options = {})
6
+ options = {:pattern => 'db/*.rb', :plural_name => nil, :singular_name => nil}.merge(options)
7
+ migration_files = Pathname.glob(options[:pattern]).sort.map { |m|
8
+ if options[:plural_name]
9
+ m = m.to_s.gsub('plural_name', options[:plural_name])
10
+ end
11
+ if options[:singular_name]
12
+ m = m.to_s.gsub('singular_name', options[:singular_name])
13
+ end
14
+ Pathname.new(m).basename.to_s.split(/^\d+_/).last
15
+ }.reject{|m| m.blank?}
16
+
17
+ if migration_files.any? and (migration_paths = Dir[Rails.root.join('db', 'migrate', "*#{migration_files.join(',')}")]).any?
18
+ message = [""]
19
+ message << "I found #{'a ' unless migration_paths.many?}migration#{'s' if migration_paths.many?} at:"
20
+ message << migration_paths.join("\n")
21
+ message << ""
22
+ message << "Please ensure that you roll back these migrations if you used them (using rake db:rollback) and then run:"
23
+ message << "\nrm #{migration_paths.join("\nrm ")}"
24
+ message << "rm #{Rails.root.join('db', 'seeds', "#{options[:plural_name]}.rb")}" if options[:plural_name]
25
+ message << "\nThis will ensure that nothing gets left behind in your database."
26
+ message << "Note - be careful about rolling back if you have any migrations created after this one."
27
+ message << "This is because Rails rolls back from the last migration backwards when rake db:rollback is invoked"
28
+ message << "\n"
29
+ puts message.join("\n")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,62 +1,9 @@
1
1
  require 'refinery'
2
+ require 'pathname'
2
3
 
3
4
  module Refinery
4
5
  module Generators
5
- # The core engine installer streamlines the installation of custom generated
6
- # engines. It takes the migrations and seeds in your engine and moves them
7
- # into the rails app db directory, ready to migrate.
8
- class EngineInstaller < Rails::Generators::Base
9
-
10
- include Rails::Generators::Migration
11
-
12
- attr_accessor :silence_puts
13
- def silence_puts
14
- !!@silence_puts
15
- end
16
-
17
- class << self
18
-
19
- def engine_name(name = nil)
20
- @engine_name = name.to_s unless name.nil?
21
- @engine_name
22
- end
23
-
24
- def source_root(root = nil)
25
- Pathname.new(super.to_s)
26
- end
27
-
28
- # Implement the required interface for Rails::Generators::Migration.
29
- # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
30
- # can be removed once this issue is fixed:
31
- # # https://rails.lighthouseapp.com/projects/8994/tickets/3820-make-railsgeneratorsmigrationnext_migration_number-method-a-class-method-so-it-possible-to-use-it-in-custom-generators
32
- def next_migration_number(dirname)
33
- ::ActiveRecord::Generators::Base.next_migration_number(dirname)
34
- end
35
- end
36
-
37
- def generate
38
- Pathname.glob(self.class.source_root.join('db', '**', '*.rb')).sort.each do |path|
39
- case path.to_s
40
- when %r{.*/migrate/.*}
41
- # unless the migration has already been generated.
42
- migration_name = "#{path.split.last.to_s.split(/\d+_/).last}"
43
- unless Dir[Rails.root.join('db', 'migrate', "*#{migration_name}")].any?
44
- migration_template path, Rails.root.join('db', 'migrate', path.to_s.split('/migrate/').last.split(/^\d*_/).last)
45
- else
46
- puts "You already have a migration called #{migration_name.split('.rb').first}" unless self.silence_puts || self.behavior == :revoke
47
- end
48
- when %r{.*/seeds/.*}
49
- template path, Rails.root.join('db', 'seeds', path.to_s.split('/seeds/').last)
50
- end
51
- end
52
-
53
- unless self.silence_puts || self.behavior == :revoke
54
- puts "------------------------"
55
- puts "Now run:"
56
- puts "rake db:migrate"
57
- puts "------------------------"
58
- end
59
- end
60
- end
6
+ autoload :EngineInstaller, File.expand_path('../generators/engine_installer', __FILE__)
7
+ autoload :Migrations, File.expand_path('../generators/migrations', __FILE__)
61
8
  end
62
9
  end
@@ -1,9 +1,8 @@
1
1
  require 'refinery'
2
+ require File.expand_path('../refinery/generators', __FILE__)
2
3
 
3
4
  module Refinery
4
5
  module Generators
5
- autoload :EngineInstaller, File.expand_path('../refinery/generators', __FILE__)
6
-
7
6
  class Engine < Rails::Engine
8
7
  config.after_initialize do
9
8
  ::Refinery::Plugin.register do |plugin|
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{refinerycms-generators}
3
- s.version = %q{0.9.9.4}
4
- s.date = %q{2011-02-17}
3
+ s.version = %q{0.9.9.5}
4
+ s.date = %q{2011-02-21}
5
5
  s.summary = %q{Core generators for the Refinery CMS project.}
6
6
  s.description = %q{Core generators for Refinery CMS including refinery_engine.}
7
7
  s.homepage = %q{http://refinerycms.com}
@@ -77,6 +77,9 @@ Gem::Specification.new do |s|
77
77
  'lib/generators/refinery_engine/templates/spec/models/singular_name_spec.rb',
78
78
  'lib/generators/refinery_engine/USAGE',
79
79
  'lib/refinery',
80
+ 'lib/refinery/generators',
81
+ 'lib/refinery/generators/engine_installer.rb',
82
+ 'lib/refinery/generators/migrations.rb',
80
83
  'lib/refinery/generators.rb',
81
84
  'lib/refinerycms-generators.rb',
82
85
  'readme.md',
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: refinerycms-generators
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.9.4
5
+ version: 0.9.9.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Resolve Digital
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-17 00:00:00 +13:00
13
+ date: 2011-02-21 00:00:00 +13:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -58,6 +58,8 @@ files:
58
58
  - lib/generators/refinery_engine/templates/refinerycms-plural_name.gemspec
59
59
  - lib/generators/refinery_engine/templates/spec/models/singular_name_spec.rb
60
60
  - lib/generators/refinery_engine/USAGE
61
+ - lib/refinery/generators/engine_installer.rb
62
+ - lib/refinery/generators/migrations.rb
61
63
  - lib/refinery/generators.rb
62
64
  - lib/refinerycms-generators.rb
63
65
  - readme.md