rails3-generators 0.15.0 → 0.16.0
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/CHANGELOG.rdoc +7 -2
- data/Gemfile.lock +1 -1
- data/README.rdoc +1 -3
- data/lib/generators/helpers/model_helper.rb +6 -35
- data/lib/rails3-generators/version.rb +1 -1
- data/rails3-generators.gemspec +8 -3
- data/test/test_helper.rb +0 -2
- metadata +10 -25
- data/lib/generators/fabrication.rb +0 -11
- data/lib/generators/fabrication/model/model_generator.rb +0 -15
- data/lib/generators/fabrication/model/templates/fabricator.rb +0 -5
- data/lib/generators/machinist.rb +0 -11
- data/lib/generators/machinist/model/model_generator.rb +0 -20
- data/lib/generators/machinist/model/templates/blueprint.rb +0 -5
- data/lib/generators/machinist/model/templates/machinist_initializer.rb +0 -19
- data/lib/generators/mongoid.rb +0 -24
- data/lib/generators/mongoid/install/install_generator.rb +0 -35
- data/lib/generators/mongoid/install/templates/database.mongo.yml +0 -25
- data/lib/generators/mongoid/install/templates/mongoid.rb +0 -12
- data/lib/generators/mongoid/model/model_generator.rb +0 -111
- data/lib/generators/mongoid/model/templates/model.rb +0 -26
- data/test/lib/generators/fabrication/model_generator_test.rb +0 -22
- data/test/lib/generators/machinist/model_generator_test.rb +0 -29
- data/test/lib/generators/mongoid/install_generator_test.rb +0 -18
- data/test/lib/generators/mongoid/model_generator_test.rb +0 -72
- data/test/lib/generators/mongoid/testing_helper.rb +0 -1
data/CHANGELOG.rdoc
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
== TODO
|
2
|
-
* Grow Mustache up.(fix the TODOs and move the source to a mustache-rails like gem)
|
3
2
|
* Write some documentation. (In both the github wiki and the source code)
|
4
|
-
*
|
3
|
+
* Remove generators that exist in other libraries
|
4
|
+
|
5
|
+
== 0.16.0
|
6
|
+
* optimize
|
7
|
+
* Machinist generators removed. Machinist 2 (https://github.com/notahat/machinist) has its own generators.
|
8
|
+
* Fabrication generators removed. Fabrication (https://github.com/paulelliott/fabrication) has its own generators.
|
9
|
+
* Mongoid generators removed. Mongoid (https://github.com/mongoid/mongoid) has its own generators.
|
5
10
|
|
6
11
|
== 0.15.0
|
7
12
|
* optimize
|
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= rails3-generators
|
2
2
|
|
3
|
-
|
3
|
+
Rails 3 compatible generators for gems that don't have them yet
|
4
4
|
|
5
5
|
== install
|
6
6
|
|
@@ -46,8 +46,6 @@ MongoMapper: Kristian Mandrup (for 0.8) - needs testing
|
|
46
46
|
|
47
47
|
Mongoid: Kristian Mandrup (for 2.0.beta) - needs testing
|
48
48
|
|
49
|
-
Machinist: Darcy Laycock
|
50
|
-
|
51
49
|
Shoulda: Peter Haza
|
52
50
|
|
53
51
|
SimpleForm: Peter Gumeson
|
@@ -5,37 +5,9 @@ module Rails3Generators
|
|
5
5
|
attr_accessor :model_attributes, :model_indexes
|
6
6
|
|
7
7
|
def parse_model_attributes(with_indexes = true)
|
8
|
-
@model_attributes = []
|
8
|
+
@model_attributes = []
|
9
9
|
@model_indexes = {}
|
10
|
-
|
11
|
-
# attributes.each do |arg|
|
12
|
-
# if with_indexes
|
13
|
-
# # extract index markers
|
14
|
-
# if arg.include?('#')
|
15
|
-
# arg.gsub! /#.*$/, ''
|
16
|
-
# model_indexes[arg_name(arg).to_sym] = true
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# if arg.include?(':')
|
21
|
-
# model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
22
|
-
# else
|
23
|
-
# model_attributes << Rails::Generators::GeneratedAttribute.new(arg, "string")
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# model_attributes.uniq!
|
27
|
-
#
|
28
|
-
# if model_attributes.empty?
|
29
|
-
# if model_exists?
|
30
|
-
# model_columns_for_attributes.each do |column|
|
31
|
-
# model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
32
|
-
# end
|
33
|
-
# else
|
34
|
-
# model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
# end
|
38
|
-
end
|
10
|
+
end
|
39
11
|
|
40
12
|
def arg_name(arg)
|
41
13
|
arg.split(':').first
|
@@ -44,11 +16,11 @@ module Rails3Generators
|
|
44
16
|
def arg_type(arg)
|
45
17
|
arg.split(':')[1] || 'string'
|
46
18
|
end
|
47
|
-
|
19
|
+
|
48
20
|
def model_name
|
49
21
|
name
|
50
|
-
end
|
51
|
-
|
22
|
+
end
|
23
|
+
|
52
24
|
def model_exists?
|
53
25
|
File.exist? destination_path("app/models/#{singular_name}.rb")
|
54
26
|
end
|
@@ -71,5 +43,4 @@ module Rails3Generators
|
|
71
43
|
end
|
72
44
|
end
|
73
45
|
end
|
74
|
-
|
75
|
-
|
46
|
+
|
data/rails3-generators.gemspec
CHANGED
@@ -7,9 +7,9 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T.", "Jai-Gouk Kim", "Darcy Laycock", "Peter Haza", "Peter Gumeson", "Kristian Mandrup", "Alejandro Juarez"]
|
9
9
|
s.email = 'andre@arko.net'
|
10
|
-
s.homepage = '
|
10
|
+
s.homepage = 'https://github.com/indirect/rails3-generators'
|
11
11
|
s.summary = 'Rails 3 compatible generators'
|
12
|
-
s.description =
|
12
|
+
s.description = "Rails 3 compatible generators for gems that don't have them yet "
|
13
13
|
|
14
14
|
s.rubyforge_project = 'rails3-generators'
|
15
15
|
s.required_rubygems_version = ">= 1.3.6"
|
@@ -28,8 +28,13 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.post_install_message = %Q{
|
29
29
|
rails3-generators-#{Rails3::Generators::VERSION}
|
30
30
|
|
31
|
-
Be sure to check out the wiki,
|
31
|
+
Be sure to check out the wiki, https://wiki.github.com/indirect/rails3-generators/,
|
32
32
|
for information about recent changes to this project.
|
33
33
|
|
34
|
+
Machinist generators have been removed. Please update your project to use Machinist 2 (https://github.com/notahat/machinist) which contains its own generators.
|
35
|
+
|
36
|
+
Fabrication generators have been removed. Please update your project to use Fabrication (https://github.com/paulelliott/fabrication) which contains its own generators.
|
37
|
+
|
38
|
+
Mongoid generators have been removed. Please update your project to use Mongoid (https://github.com/mongoid/mongoid) which contains its own generators.
|
34
39
|
}
|
35
40
|
end
|
data/test/test_helper.rb
CHANGED
@@ -51,9 +51,7 @@ def generator_list
|
|
51
51
|
:erubis => ['scaffold'],
|
52
52
|
:simple_form => ['scaffold'],
|
53
53
|
:formtastic => ['scaffold'],
|
54
|
-
:fabrication => ['model'],
|
55
54
|
:factory_girl => ['model'],
|
56
|
-
:machinist => ['model'],
|
57
55
|
:authlogic => ['session'],
|
58
56
|
:koala => ['install'],
|
59
57
|
:shoulda => ['controller']
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 16
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.16.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jose Valim
|
@@ -83,7 +83,7 @@ dependencies:
|
|
83
83
|
version: "0"
|
84
84
|
type: :development
|
85
85
|
version_requirements: *id004
|
86
|
-
description: Rails 3 compatible generators for
|
86
|
+
description: "Rails 3 compatible generators for gems that don't have them yet "
|
87
87
|
email: andre@arko.net
|
88
88
|
executables: []
|
89
89
|
|
@@ -119,9 +119,6 @@ files:
|
|
119
119
|
- lib/generators/erubis/scaffold/templates/index.html.erb
|
120
120
|
- lib/generators/erubis/scaffold/templates/new.html.erb
|
121
121
|
- lib/generators/erubis/scaffold/templates/show.html.erb
|
122
|
-
- lib/generators/fabrication.rb
|
123
|
-
- lib/generators/fabrication/model/model_generator.rb
|
124
|
-
- lib/generators/fabrication/model/templates/fabricator.rb
|
125
122
|
- lib/generators/factory_girl.rb
|
126
123
|
- lib/generators/factory_girl/model/model_generator.rb
|
127
124
|
- lib/generators/factory_girl/model/templates/fixtures.rb
|
@@ -136,10 +133,6 @@ files:
|
|
136
133
|
- lib/generators/koala/install/templates/app/helpers/facebook_helper.rb.tt
|
137
134
|
- lib/generators/koala/install/templates/config/facebook.yml.tt
|
138
135
|
- lib/generators/koala/install/templates/config/initializers/koala.rb.tt
|
139
|
-
- lib/generators/machinist.rb
|
140
|
-
- lib/generators/machinist/model/model_generator.rb
|
141
|
-
- lib/generators/machinist/model/templates/blueprint.rb
|
142
|
-
- lib/generators/machinist/model/templates/machinist_initializer.rb
|
143
136
|
- lib/generators/mongo_mapper.rb
|
144
137
|
- lib/generators/mongo_mapper/.DS_Store
|
145
138
|
- lib/generators/mongo_mapper/install/install_generator.rb
|
@@ -149,12 +142,6 @@ files:
|
|
149
142
|
- lib/generators/mongo_mapper/model/templates/model.rb
|
150
143
|
- lib/generators/mongo_mapper/observer/observer_generator.rb
|
151
144
|
- lib/generators/mongo_mapper/observer/templates/observer.rb
|
152
|
-
- lib/generators/mongoid.rb
|
153
|
-
- lib/generators/mongoid/install/install_generator.rb
|
154
|
-
- lib/generators/mongoid/install/templates/database.mongo.yml
|
155
|
-
- lib/generators/mongoid/install/templates/mongoid.rb
|
156
|
-
- lib/generators/mongoid/model/model_generator.rb
|
157
|
-
- lib/generators/mongoid/model/templates/model.rb
|
158
145
|
- lib/generators/mustache.rb
|
159
146
|
- lib/generators/mustache/README.md
|
160
147
|
- lib/generators/mustache/controller/controller_generator.rb
|
@@ -192,18 +179,13 @@ files:
|
|
192
179
|
- test/lib/generators/data_mapper/observer_generator_test.rb
|
193
180
|
- test/lib/generators/erubis/controller_generator_test.rb
|
194
181
|
- test/lib/generators/erubis/scaffold_generator_test.rb
|
195
|
-
- test/lib/generators/fabrication/model_generator_test.rb
|
196
182
|
- test/lib/generators/factory_girl/model_generator_test.rb
|
197
183
|
- test/lib/generators/formtastic/scaffold_generators_test.rb
|
198
184
|
- test/lib/generators/koala/install_generator_test.rb
|
199
|
-
- test/lib/generators/machinist/model_generator_test.rb
|
200
185
|
- test/lib/generators/mongo_mapper/install_generator_test.rb
|
201
186
|
- test/lib/generators/mongo_mapper/model_generator_test.rb
|
202
187
|
- test/lib/generators/mongo_mapper/observer_generator_test.rb
|
203
188
|
- test/lib/generators/mongo_mapper/testing_helper.rb
|
204
|
-
- test/lib/generators/mongoid/install_generator_test.rb
|
205
|
-
- test/lib/generators/mongoid/model_generator_test.rb
|
206
|
-
- test/lib/generators/mongoid/testing_helper.rb
|
207
189
|
- test/lib/generators/mustache/controller_generator_test.rb
|
208
190
|
- test/lib/generators/mustache/scaffold_generator_test.rb
|
209
191
|
- test/lib/generators/mustache/testing_helper.rb
|
@@ -211,13 +193,16 @@ files:
|
|
211
193
|
- test/lib/generators/simple_form/scaffold_generators_test.rb
|
212
194
|
- test/test_helper.rb
|
213
195
|
has_rdoc: true
|
214
|
-
homepage:
|
196
|
+
homepage: https://github.com/indirect/rails3-generators
|
215
197
|
licenses: []
|
216
198
|
|
217
199
|
post_install_message: "\n\
|
218
|
-
rails3-generators-0.
|
219
|
-
Be sure to check out the wiki,
|
220
|
-
for information about recent changes to this project.\n\n
|
200
|
+
rails3-generators-0.16.0\n\n\
|
201
|
+
Be sure to check out the wiki, https://wiki.github.com/indirect/rails3-generators/,\n\
|
202
|
+
for information about recent changes to this project.\n\n\
|
203
|
+
Machinist generators have been removed. Please update your project to use Machinist 2 (https://github.com/notahat/machinist) which contains its own generators.\n\n\
|
204
|
+
Fabrication generators have been removed. Please update your project to use Fabrication (https://github.com/paulelliott/fabrication) which contains its own generators.\n\n\
|
205
|
+
Mongoid generators have been removed. Please update your project to use Mongoid (https://github.com/mongoid/mongoid) which contains its own generators.\n"
|
221
206
|
rdoc_options: []
|
222
207
|
|
223
208
|
require_paths:
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'rails/generators/named_base'
|
2
|
-
|
3
|
-
module Fabrication
|
4
|
-
module Generators
|
5
|
-
class Base < Rails::Generators::NamedBase #:nodoc:
|
6
|
-
def self.source_root
|
7
|
-
@_fabrication_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'fabrication', generator_name, 'templates'))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'generators/fabrication'
|
2
|
-
|
3
|
-
module Fabrication
|
4
|
-
module Generators
|
5
|
-
class ModelGenerator < Base
|
6
|
-
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
-
class_option :dir, :type => :string, :default => "test/fabricators", :desc => "The directory where the blueprints should go"
|
8
|
-
class_option :extension, :type => :string, :default => "rb", :desc => "file extension name"
|
9
|
-
|
10
|
-
def create_fabrication_file
|
11
|
-
template 'fabricator.rb', File.join(options[:dir], "#{table_name}.#{options[:extension].to_s}")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/generators/machinist.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'rails/generators/named_base'
|
2
|
-
|
3
|
-
module Machinist
|
4
|
-
module Generators
|
5
|
-
class Base < Rails::Generators::NamedBase #:nodoc:
|
6
|
-
def self.source_root
|
7
|
-
@_machinist_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'machinist', generator_name, 'templates'))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'generators/machinist'
|
2
|
-
|
3
|
-
module Machinist
|
4
|
-
module Generators
|
5
|
-
class ModelGenerator < Base
|
6
|
-
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
-
class_option :dir, :type => :string, :default => "test/blueprints", :desc => "The directory where the blueprints should go"
|
8
|
-
class_option :extension, :type => :string, :default => "rb", :desc => "file extension name"
|
9
|
-
|
10
|
-
def create_machinist_initializer
|
11
|
-
return if File.exists?(File.expand_path("config/initializers/machinist.rb", self.destination_root))
|
12
|
-
template "machinist_initializer.rb", "config/initializers/machinist.rb"
|
13
|
-
end
|
14
|
-
|
15
|
-
def create_blueprint_file
|
16
|
-
template 'blueprint.rb', File.join(options[:dir], "#{table_name}.#{options[:extension].to_s}")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# Add other envs here e.g. cucumber
|
2
|
-
if Rails.env.test?
|
3
|
-
require 'machinist'
|
4
|
-
# require 'machinist/active_record'
|
5
|
-
|
6
|
-
def Machinist.clear!
|
7
|
-
Sham.clear
|
8
|
-
# ActiveRecord::Base.clear_blueprints!
|
9
|
-
end
|
10
|
-
|
11
|
-
def Machinist.load_blueprints
|
12
|
-
Dir[Rails.root.join(<%= options[:dir].inspect %>, "**", "*.rb")].each do |file|
|
13
|
-
load file
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Put Machinist.load_blueprints in the test_helper.rb
|
18
|
-
|
19
|
-
end
|
data/lib/generators/mongoid.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'rails/generators/named_base'
|
2
|
-
require 'rails/generators/active_model'
|
3
|
-
|
4
|
-
module Mongoid
|
5
|
-
module Generators
|
6
|
-
class Base < Rails::Generators::NamedBase #:nodoc:
|
7
|
-
|
8
|
-
def self.source_root
|
9
|
-
@_mongoid_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'mongoid', generator_name, 'templates'))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
module Rails
|
16
|
-
module Generators
|
17
|
-
class GeneratedAttribute #:nodoc:
|
18
|
-
def type_class
|
19
|
-
return 'DateTime' if type.to_s == 'datetime'
|
20
|
-
return type.to_s.camelcase
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'rails/generators/base'
|
2
|
-
require 'generators/mongoid'
|
3
|
-
|
4
|
-
module Mongoid
|
5
|
-
module Generators
|
6
|
-
class InstallGenerator < Base
|
7
|
-
|
8
|
-
# argument :database, :type => :string, :default => 'mongo_db_default', :desc => "Name of the Mongo database to use"
|
9
|
-
class_option :host, :type => :string, :default => 'localhost', :desc => "Name of the Mongo host use"
|
10
|
-
|
11
|
-
def create_files
|
12
|
-
template "mongoid.rb", "config/initializers/mongoid.rb"
|
13
|
-
template 'database.mongo.yml', "config/database.mongo.yml"
|
14
|
-
|
15
|
-
puts "Please ensure Gemfile contains: gem '#{orm_gem_name}', '>=2.0.0.beta9'"
|
16
|
-
say "For production enviroment DB configuration, set environment variables as indicated in config/database.mongo.yml"
|
17
|
-
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
|
21
|
-
def database
|
22
|
-
name
|
23
|
-
end
|
24
|
-
|
25
|
-
def orm_gem_name
|
26
|
-
"mongoid"
|
27
|
-
end
|
28
|
-
|
29
|
-
def host
|
30
|
-
options[:host] || 'localhost'
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
defaults: &defaults
|
2
|
-
adapter: mongodb
|
3
|
-
host: <%= host %>
|
4
|
-
# slaves:
|
5
|
-
# - host: slave1.local
|
6
|
-
# port: 27018
|
7
|
-
# - host: slave2.local
|
8
|
-
# port: 27019
|
9
|
-
|
10
|
-
development:
|
11
|
-
<<: *defaults
|
12
|
-
database: <%= database %>_development
|
13
|
-
|
14
|
-
test:
|
15
|
-
<<: *defaults
|
16
|
-
database: <%= database %>_test
|
17
|
-
|
18
|
-
# set these environment variables on your prod server
|
19
|
-
production:
|
20
|
-
<<: *defaults
|
21
|
-
host: <%= ENV['MONGOID_HOST'] %>
|
22
|
-
port: <%= ENV['MONGOID_PORT'] %>
|
23
|
-
username: <%= ENV['MONGOID_USERNAME'] %>
|
24
|
-
password: <%= ENV['MONGOID_PASSWORD'] %>
|
25
|
-
database: <%= ENV['MONGOID_DATABASE'] %>
|
@@ -1,12 +0,0 @@
|
|
1
|
-
database_config_file = File.join(Rails.root, "/config/database.mongo.yml")
|
2
|
-
yaml_content = File.read(database_config_file)
|
3
|
-
db_config = YAML::load(yaml_content)
|
4
|
-
|
5
|
-
if db_config[Rails.env] && db_config[Rails.env]['adapter'] == 'mongodb'
|
6
|
-
mongo = db_config[Rails.env]
|
7
|
-
connection = Mongo::Connection.new(mongo['host'])
|
8
|
-
Mongoid.database = connection.db(mongo["database"])
|
9
|
-
if mongo["username"]
|
10
|
-
Mongoid.database.authenticate(mongo["username"], mongo["password"])
|
11
|
-
end
|
12
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'generators/mongoid'
|
2
|
-
|
3
|
-
module Mongoid
|
4
|
-
module Generators
|
5
|
-
class ModelGenerator < Base
|
6
|
-
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
-
|
8
|
-
class_option :embedded_in, :type => :string, :aliases => "-E", :desc => "Class name of document this document is embedded in"
|
9
|
-
class_option :parent, :type => :string, :aliases => "-P", :desc => "Class name of parent document"
|
10
|
-
class_option :timestamps, :type => :boolean, :aliases => "-T", :desc => "Add timestamps created_at and updated_at", :default => false
|
11
|
-
class_option :version, :type => :boolean, :aliases => "-V", :desc => "Add versioning", :default => false
|
12
|
-
class_option :enslave, :type => :boolean, :aliases => "-S", :desc => "Add enslavement", :default => false
|
13
|
-
class_option :cache, :type => :boolean, :aliases => "-C", :desc => "Add Caching", :default => false
|
14
|
-
|
15
|
-
class_option :index, :type => :array, :aliases => "-I", :desc => "Keys to index", :default => []
|
16
|
-
|
17
|
-
def create_model_file
|
18
|
-
template('model.rb', "app/models/#{file_name}.rb") if valid_model_name?(file_name)
|
19
|
-
end
|
20
|
-
|
21
|
-
protected
|
22
|
-
|
23
|
-
def valid_model_name?(name)
|
24
|
-
(name =~ /("|'|:|;|\||&|<|>)/).nil?
|
25
|
-
end
|
26
|
-
|
27
|
-
def embedded?
|
28
|
-
options[:embedded_in]
|
29
|
-
end
|
30
|
-
|
31
|
-
def enslave?
|
32
|
-
options[:enslave]
|
33
|
-
end
|
34
|
-
|
35
|
-
def cache?
|
36
|
-
options[:cache]
|
37
|
-
end
|
38
|
-
|
39
|
-
def parent?
|
40
|
-
options[:parent]
|
41
|
-
end
|
42
|
-
|
43
|
-
def parent
|
44
|
-
options[:parent]
|
45
|
-
end
|
46
|
-
|
47
|
-
def timestamps?
|
48
|
-
options[:timestamps]
|
49
|
-
end
|
50
|
-
|
51
|
-
def version?
|
52
|
-
options[:version]
|
53
|
-
end
|
54
|
-
|
55
|
-
def indexes
|
56
|
-
options[:index] || []
|
57
|
-
end
|
58
|
-
|
59
|
-
def indexes?
|
60
|
-
!indexes.empty?
|
61
|
-
end
|
62
|
-
|
63
|
-
def has_key?(key)
|
64
|
-
attribute_names.include?(key)
|
65
|
-
end
|
66
|
-
|
67
|
-
def attribute_names
|
68
|
-
attributes.map { |key| key.name}
|
69
|
-
end
|
70
|
-
|
71
|
-
def write_indexes
|
72
|
-
say "write_indexes", :green
|
73
|
-
if indexes?
|
74
|
-
idx = indexes.map { |key| " index :#{key}, :unique => true" if has_key?(key) }
|
75
|
-
say "indexes: #{idx}"
|
76
|
-
idx.join("\n")
|
77
|
-
else
|
78
|
-
say "no indexes"
|
79
|
-
nil
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def extra_statements
|
84
|
-
stm_list = []
|
85
|
-
stm_list << " cache" if cache?
|
86
|
-
stm_list << " enslave" if enslave?
|
87
|
-
stm_list.join("\n")
|
88
|
-
end
|
89
|
-
|
90
|
-
def statements
|
91
|
-
stm_list = []
|
92
|
-
stm_list << embedded_statement if embedded?
|
93
|
-
stm_list << version_statement if version?
|
94
|
-
stm_list << timestamps_statement if timestamps?
|
95
|
-
stm_list.join("\n")
|
96
|
-
end
|
97
|
-
|
98
|
-
def embedded_statement
|
99
|
-
"embedded_in :#{options[:embedded_in].underscore}, :inverse_of => :#{class_name.pluralize.underscore}"
|
100
|
-
end
|
101
|
-
|
102
|
-
def version_statement
|
103
|
-
"include Mongoid::Versioning"
|
104
|
-
end
|
105
|
-
|
106
|
-
def timestamps_statement
|
107
|
-
"include Mongoid::Timestamps"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
class <%= class_name %><%= "< #{parent.classify}" if parent? %>
|
2
|
-
<% unless parent? -%>
|
3
|
-
include Mongoid::Document
|
4
|
-
<% end -%>
|
5
|
-
<%= statements %>
|
6
|
-
<% unless parent? -%>
|
7
|
-
# Validations :::::::::::::::::::::::::::::::::::::::::::::::::::::
|
8
|
-
# validates_presence_of :attribute
|
9
|
-
|
10
|
-
# Assocations :::::::::::::::::::::::::::::::::::::::::::::::::::::
|
11
|
-
# belongs_to :model
|
12
|
-
# embeds_many :model
|
13
|
-
# embeds_one :model
|
14
|
-
|
15
|
-
# Callbacks :::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
16
|
-
# before_create :your_model_method
|
17
|
-
# after_create :your_model_method
|
18
|
-
# before_update :your_model_method
|
19
|
-
|
20
|
-
<% end -%>
|
21
|
-
<% attributes.each do |attribute| -%>
|
22
|
-
field :<%= attribute.name %>, :type => <%= attribute.type_class %>
|
23
|
-
<% end -%>
|
24
|
-
<%= write_indexes -%>
|
25
|
-
<%= extra_statements -%>
|
26
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class Fabrication::Generators::ModelGeneratorTest < Rails::Generators::TestCase
|
4
|
-
destination File.join(Rails.root)
|
5
|
-
tests Rails::Generators::ModelGenerator
|
6
|
-
arguments %w(Account name:string age:integer -r fabrication)
|
7
|
-
|
8
|
-
setup :prepare_destination
|
9
|
-
setup :copy_routes
|
10
|
-
|
11
|
-
test "invoke when fixture replacement is given" do
|
12
|
-
run_generator
|
13
|
-
assert_file "test/fabricators/accounts.rb"
|
14
|
-
assert_no_file "test/fixtures/accounts.yml"
|
15
|
-
end
|
16
|
-
|
17
|
-
test "invoke when fixture replacement is given with custom dir" do
|
18
|
-
content = run_generator %w(Account name:string age:integer -r fabrication --dir custom/fabricators)
|
19
|
-
assert_file "custom/fabricators/accounts.rb"
|
20
|
-
assert_no_file "test/fixtures/accounts.yml"
|
21
|
-
end
|
22
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class Machinist::Generators::ModelGeneratorTest < Rails::Generators::TestCase
|
4
|
-
destination File.join(Rails.root)
|
5
|
-
tests Rails::Generators::ModelGenerator
|
6
|
-
arguments %w(Account name:string age:integer -r machinist)
|
7
|
-
|
8
|
-
setup :prepare_destination
|
9
|
-
setup :copy_routes
|
10
|
-
|
11
|
-
test "invoke when fixture replacement is given" do
|
12
|
-
run_generator
|
13
|
-
assert_file "test/blueprints/accounts.rb"
|
14
|
-
assert_file "config/initializers/machinist.rb"
|
15
|
-
assert_no_file "test/fixtures/accounts.yml"
|
16
|
-
end
|
17
|
-
|
18
|
-
test "invoke when fixture replacement is given with custom dir" do
|
19
|
-
content = run_generator %w(Account name:string age:integer -r machinist --dir custom/blueprints)
|
20
|
-
assert_file "custom/blueprints/accounts.rb"
|
21
|
-
assert_file "config/initializers/machinist.rb"
|
22
|
-
assert_no_file "test/fixtures/accounts.yml"
|
23
|
-
end
|
24
|
-
|
25
|
-
test "invoke when fixture replacement is given with custom file extenstion" do
|
26
|
-
content = run_generator %w(Account name:string age:integer -r machinist --extension i.like.using.blueprint)
|
27
|
-
assert_file "test/blueprints/accounts.i.like.using.blueprint"
|
28
|
-
end
|
29
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'lib/generators/mongoid/testing_helper'
|
3
|
-
|
4
|
-
class Mongoid::Generators::InstallGeneratorTest < Rails::Generators::TestCase
|
5
|
-
destination File.join(Rails.root)
|
6
|
-
tests Mongoid::Generators::InstallGenerator
|
7
|
-
|
8
|
-
setup :prepare_destination
|
9
|
-
setup :copy_routes
|
10
|
-
|
11
|
-
test "invoke" do
|
12
|
-
run_generator ['test-db']
|
13
|
-
|
14
|
-
assert_file "config/initializers/mongoid.rb" do |initializer|
|
15
|
-
assert_match /Mongo::Connection.new(\S+)/, initializer
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'lib/generators/mongoid/testing_helper'
|
3
|
-
|
4
|
-
class Mongoid::Generators::ModelGeneratorTest < Rails::Generators::TestCase
|
5
|
-
destination File.join(Rails.root)
|
6
|
-
tests Mongoid::Generators::ModelGenerator
|
7
|
-
|
8
|
-
setup :prepare_destination
|
9
|
-
setup :copy_routes
|
10
|
-
|
11
|
-
test "invoke with model name" do
|
12
|
-
content = run_generator %w(Account)
|
13
|
-
|
14
|
-
assert_file "app/models/account.rb" do |account|
|
15
|
-
assert_class "Account", account do |klass|
|
16
|
-
assert_match /Mongoid::Document/, klass
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
test "invoke with model name and attributes" do
|
22
|
-
content = run_generator %w(Account name:string age:integer)
|
23
|
-
|
24
|
-
assert_file "app/models/account.rb" do |account|
|
25
|
-
assert_class "Account", account do |klass|
|
26
|
-
assert_match /field :name, :type => String/, klass
|
27
|
-
assert_match /field :age, :type => Integer/, klass
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
test "invoke with model name and --embedded_in option" do
|
33
|
-
content = run_generator %w(Room --embedded-in House)
|
34
|
-
|
35
|
-
assert_file "app/models/room.rb" do |account|
|
36
|
-
assert_class "Room", account do |klass|
|
37
|
-
assert_match /embedded_in :house, :inverse_of => :rooms/, klass
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
test "invoke with model name and --timestamps option" do
|
43
|
-
content = run_generator %w(Account --timestamps)
|
44
|
-
|
45
|
-
assert_file "app/models/account.rb" do |account|
|
46
|
-
assert_class "Account", account do |klass|
|
47
|
-
assert_match /include Mongoid::Timestamps/, klass
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
test "invoke with model name and --version option" do
|
53
|
-
content = run_generator %w(Account --version)
|
54
|
-
|
55
|
-
assert_file "app/models/account.rb" do |account|
|
56
|
-
assert_class "Account", account do |klass|
|
57
|
-
assert_match /include Mongoid::Versioning/, klass
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
test "invoke with model name and --parent option" do
|
63
|
-
content = run_generator %w(Admin --parent User)
|
64
|
-
|
65
|
-
assert_file "app/models/admin.rb" do |account|
|
66
|
-
assert_class "Admin", account do |klass|
|
67
|
-
assert_no_match /Mongoid::Document/, klass
|
68
|
-
assert_match /<\s+User/, klass
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require_generators :mongoid => ['model', 'install']
|