rails3-generators 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 +3 -1
- data/VERSION +1 -1
- data/lib/generators/mongomapper.rb +80 -0
- data/lib/generators/mongomapper/model/model_generator.rb +29 -0
- data/lib/generators/mongomapper/model/templates/model.rb +26 -0
- data/lib/generators/mongomapper/observer/observer_generator.rb +15 -0
- data/lib/generators/rspec/model/templates/model_spec.rb +2 -1
- data/rails3-generators.gemspec +5 -1
- metadata +5 -1
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
# require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/active_model'
|
4
|
+
|
5
|
+
module Mongomapper
|
6
|
+
module Generators
|
7
|
+
class Base < Rails::Generators::NamedBase #:nodoc:
|
8
|
+
# include Rails::Generators::Migration
|
9
|
+
|
10
|
+
def self.source_root
|
11
|
+
@_mongomapper_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
|
12
|
+
'mongomapper', generator_name, 'templates'))
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
# # mongomapper does not care if migrations have the same name as long as
|
18
|
+
# # they have different ids.
|
19
|
+
# #
|
20
|
+
# def migration_exists?(dirname, file_name) #:nodoc:
|
21
|
+
# false
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# # Implement the required interface for Rails::Generators::Migration.
|
25
|
+
# #
|
26
|
+
# def next_migration_number(dirname) #:nodoc:
|
27
|
+
# if options[:id]
|
28
|
+
# "%.3d" % options[:id]
|
29
|
+
# else
|
30
|
+
# "%.3d" % (current_migration_number(dirname) + 1)
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
end
|
34
|
+
|
35
|
+
class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
|
36
|
+
def self.all(klass)
|
37
|
+
"#{klass}.all"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.find(klass, params=nil)
|
41
|
+
"#{klass}.first(#{params})"
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.build(klass, params=nil)
|
45
|
+
if params
|
46
|
+
"#{klass}.new(#{params})"
|
47
|
+
else
|
48
|
+
"#{klass}.new"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def save
|
53
|
+
"#{name}.save"
|
54
|
+
end
|
55
|
+
|
56
|
+
def update_attributes(params=nil)
|
57
|
+
"#{name}.update(#{params})"
|
58
|
+
end
|
59
|
+
|
60
|
+
def errors
|
61
|
+
"#{name}.errors"
|
62
|
+
end
|
63
|
+
|
64
|
+
def destroy
|
65
|
+
"#{name}.destroy"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
module Rails
|
72
|
+
module Generators
|
73
|
+
class GeneratedAttribute #:nodoc:
|
74
|
+
def type_class
|
75
|
+
return 'DateTime' if type.to_s == 'datetime'
|
76
|
+
return type.to_s.camelcase
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'generators/mongomapper'
|
2
|
+
|
3
|
+
module Mongomapper
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
# class_option :_id, :type => :numeric, :desc => "The id to used in the migration"
|
8
|
+
|
9
|
+
check_class_collision
|
10
|
+
|
11
|
+
# class_option :migration, :type => :boolean
|
12
|
+
class_option :timestamps, :type => :boolean
|
13
|
+
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
14
|
+
|
15
|
+
# def create_migration_file
|
16
|
+
# if options[:migration] && options[:parent].nil?
|
17
|
+
# file_name = "create_#{file_path.gsub(/\//, '_').pluralize}"
|
18
|
+
# migration_template "migration.rb", "db/migrate/#{file_name}.rb"
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
|
22
|
+
def create_model_file
|
23
|
+
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
24
|
+
end
|
25
|
+
|
26
|
+
hook_for :test_framework
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class <%= class_name %><%= "< #{options[:parent].classify}" if options[:parent] %>
|
2
|
+
<% unless options[:parent] -%>
|
3
|
+
include MongoMapper::Document
|
4
|
+
|
5
|
+
key :key, String
|
6
|
+
|
7
|
+
timestamps!
|
8
|
+
|
9
|
+
# Validations :::::::::::::::::::::::::::::::::::::::::::::::::::::
|
10
|
+
# validates_presence_of :attribute
|
11
|
+
|
12
|
+
# Assocations :::::::::::::::::::::::::::::::::::::::::::::::::::::
|
13
|
+
# belongs_to :model
|
14
|
+
# many :model
|
15
|
+
# one :model
|
16
|
+
|
17
|
+
# Callbacks :::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
18
|
+
# before_craete :your_model_method
|
19
|
+
# after_create :your_model_method
|
20
|
+
# before_upate :your_model_method
|
21
|
+
|
22
|
+
<% end -%>
|
23
|
+
<% attributes.each do |attribute| -%>
|
24
|
+
key :<%= attribute.name %>, <%= attribute.type_class %>
|
25
|
+
<% end -%>
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'generators/mongomapper'
|
2
|
+
|
3
|
+
module MongoMapper
|
4
|
+
module Generators
|
5
|
+
class ObserverGenerator < Base
|
6
|
+
check_class_collision :suffix => "Observer"
|
7
|
+
|
8
|
+
def create_observer_file
|
9
|
+
template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb")
|
10
|
+
end
|
11
|
+
|
12
|
+
hook_for :test_framework
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
vrequire File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
2
2
|
|
3
3
|
describe <%= class_name %> do
|
4
4
|
before(:each) do
|
@@ -11,3 +11,4 @@ describe <%= class_name %> do
|
|
11
11
|
<%= class_name %>.create!(@valid_attributes)
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
data/rails3-generators.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails3-generators}
|
8
|
-
s.version = "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 = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T."]
|
@@ -44,6 +44,10 @@ Gem::Specification.new do |s|
|
|
44
44
|
"lib/generators/haml/scaffold/templates/layout.haml.erb",
|
45
45
|
"lib/generators/haml/scaffold/templates/new.haml.erb",
|
46
46
|
"lib/generators/haml/scaffold/templates/show.haml.erb",
|
47
|
+
"lib/generators/mongomapper.rb",
|
48
|
+
"lib/generators/mongomapper/model/model_generator.rb",
|
49
|
+
"lib/generators/mongomapper/model/templates/model.rb",
|
50
|
+
"lib/generators/mongomapper/observer/observer_generator.rb",
|
47
51
|
"lib/generators/rspec.rb",
|
48
52
|
"lib/generators/rspec/controller/controller_generator.rb",
|
49
53
|
"lib/generators/rspec/controller/templates/controller_spec.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails3-generators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Valim
|
@@ -63,6 +63,10 @@ files:
|
|
63
63
|
- lib/generators/haml/scaffold/templates/layout.haml.erb
|
64
64
|
- lib/generators/haml/scaffold/templates/new.haml.erb
|
65
65
|
- lib/generators/haml/scaffold/templates/show.haml.erb
|
66
|
+
- lib/generators/mongomapper.rb
|
67
|
+
- lib/generators/mongomapper/model/model_generator.rb
|
68
|
+
- lib/generators/mongomapper/model/templates/model.rb
|
69
|
+
- lib/generators/mongomapper/observer/observer_generator.rb
|
66
70
|
- lib/generators/rspec.rb
|
67
71
|
- lib/generators/rspec/controller/controller_generator.rb
|
68
72
|
- lib/generators/rspec/controller/templates/controller_spec.rb
|