rails3-generators 0.16.1 → 0.17.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 +13 -0
- data/Gemfile.lock +1 -1
- data/lib/generators/active_model/model/model_generator.rb +41 -0
- data/lib/generators/active_model/model/templates/model.rb +13 -0
- data/lib/generators/active_model.rb +32 -0
- data/lib/rails3-generators/version.rb +1 -1
- data/lib/rails3-generators.rb +1 -1
- data/test/lib/generators/active_model/model_generator_test.rb +35 -0
- metadata +9 -5
data/CHANGELOG.rdoc
CHANGED
@@ -2,6 +2,19 @@
|
|
2
2
|
* Write some documentation. (In both the github wiki and the source code)
|
3
3
|
* Remove generators that exist in other libraries
|
4
4
|
|
5
|
+
== 0.17.0
|
6
|
+
* enhancements
|
7
|
+
* Added a generator for creating models with no persistent.
|
8
|
+
They still include ActiveModel::Validations and ActiveModel::Serialization.
|
9
|
+
|
10
|
+
When generating properties you can use the following as types to create the required accessor
|
11
|
+
|
12
|
+
read - generate read_accessor
|
13
|
+
write - generate write_accessor
|
14
|
+
all - generate attr_accessor
|
15
|
+
|
16
|
+
(Colin Gemmel)
|
17
|
+
|
5
18
|
== 0.16.0
|
6
19
|
* optimize
|
7
20
|
* Machinist generators removed. Machinist 2 (https://github.com/notahat/machinist) has its own generators.
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'generators/active_model'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
|
8
|
+
check_class_collision
|
9
|
+
|
10
|
+
def create_model_file
|
11
|
+
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
12
|
+
end
|
13
|
+
|
14
|
+
def read_properties?
|
15
|
+
attributes.any?{|attr| attr.type == :read }
|
16
|
+
end
|
17
|
+
|
18
|
+
def read_properties
|
19
|
+
attributes.select{|attr| attr.type == :read}.map{|attr| ":#{attr.name}" }.join(",")
|
20
|
+
end
|
21
|
+
|
22
|
+
def write_properties?
|
23
|
+
attributes.any?{|attr| attr.type == :write }
|
24
|
+
end
|
25
|
+
|
26
|
+
def write_properties
|
27
|
+
attributes.select{|attr| attr.type == :write }.map{|attr| ":#{attr.name}" }.join(",")
|
28
|
+
end
|
29
|
+
|
30
|
+
def accessor_properties?
|
31
|
+
attributes.any?{|attr| attr.type == :all }
|
32
|
+
end
|
33
|
+
|
34
|
+
def accessor_properties
|
35
|
+
attributes.select{|attr| attr.type == :all }.map{|attr| ":#{attr.name}" }.join(",")
|
36
|
+
end
|
37
|
+
|
38
|
+
hook_for :test_framework
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class <%= class_name %>
|
2
|
+
include ActiveModel::Serialization
|
3
|
+
include ActiveModel::Validations
|
4
|
+
<% if read_properties? %>
|
5
|
+
attr_reader <%= read_properties %>
|
6
|
+
<% end %>
|
7
|
+
<% if write_properties? %>
|
8
|
+
attr_writer <%= write_properties %>
|
9
|
+
<% end %>
|
10
|
+
<% if accessor_properties? %>
|
11
|
+
attr_accessor <%= accessor_properties %>
|
12
|
+
<% end %>
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/active_model'
|
4
|
+
|
5
|
+
require 'generators/helpers/migration_helper'
|
6
|
+
|
7
|
+
module ActiveModel
|
8
|
+
module Generators
|
9
|
+
class Base < Rails::Generators::NamedBase #:nodoc:
|
10
|
+
|
11
|
+
def self.source_root
|
12
|
+
@_activemodel_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
|
13
|
+
'active_model', generator_name, 'templates'))
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Rails
|
24
|
+
module Generators
|
25
|
+
class GeneratedAttribute #:nodoc:
|
26
|
+
def type_class
|
27
|
+
return 'DateTime' if type.to_s == 'datetime'
|
28
|
+
return type.to_s.camelcase
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/rails3-generators.rb
CHANGED
@@ -5,7 +5,7 @@ end
|
|
5
5
|
|
6
6
|
Rails::Generators.hidden_namespaces << "rails"
|
7
7
|
|
8
|
-
%w(active_record data_mapper mongo_mapper mongoid).each do |orm|
|
8
|
+
%w(active_record data_mapper mongo_mapper mongoid active_model).each do |orm|
|
9
9
|
Rails::Generators.hidden_namespaces <<
|
10
10
|
[
|
11
11
|
"#{orm}:migration",
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require_generator :active_model => ['model']
|
3
|
+
|
4
|
+
class ActiveModel::Generators::ModelGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests ActiveModel::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 /include ActiveModel::Validations/, klass
|
17
|
+
assert_match /include ActiveModel::Serialization/, klass
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
test "invoke with model name and accessors" do
|
23
|
+
content = run_generator %w(Account name:all age:read color:write )
|
24
|
+
|
25
|
+
assert_file "app/models/account.rb" do |account|
|
26
|
+
assert_class "Account", account do |klass|
|
27
|
+
assert_match /include ActiveModel::Validations/, klass
|
28
|
+
assert_match /include ActiveModel::Serialization/, klass
|
29
|
+
assert_match /attr_reader :age/, klass
|
30
|
+
assert_match /attr_writer :color/, klass
|
31
|
+
assert_match /attr_accessor :name/, klass
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 17
|
8
|
+
- 0
|
9
|
+
version: 0.17.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jose Valim
|
@@ -24,7 +24,7 @@ autorequire:
|
|
24
24
|
bindir: bin
|
25
25
|
cert_chain: []
|
26
26
|
|
27
|
-
date: 2010-12-
|
27
|
+
date: 2010-12-13 00:00:00 -05:00
|
28
28
|
default_executable:
|
29
29
|
dependencies:
|
30
30
|
- !ruby/object:Gem::Dependency
|
@@ -114,6 +114,9 @@ files:
|
|
114
114
|
- Gemfile.lock
|
115
115
|
- README.rdoc
|
116
116
|
- Rakefile
|
117
|
+
- lib/generators/active_model.rb
|
118
|
+
- lib/generators/active_model/model/model_generator.rb
|
119
|
+
- lib/generators/active_model/model/templates/model.rb
|
117
120
|
- lib/generators/authlogic.rb
|
118
121
|
- lib/generators/authlogic/session/session_generator.rb
|
119
122
|
- lib/generators/authlogic/session/templates/session.rb
|
@@ -188,6 +191,7 @@ files:
|
|
188
191
|
- lib/rails3-generators/version.rb
|
189
192
|
- rails3-generators.gemspec
|
190
193
|
- test/fixtures/routes.rb
|
194
|
+
- test/lib/generators/active_model/model_generator_test.rb
|
191
195
|
- test/lib/generators/authlogic/session_generator_test.rb
|
192
196
|
- test/lib/generators/data_mapper/migration_generator_test.rb
|
193
197
|
- test/lib/generators/data_mapper/model_generator_test.rb
|
@@ -212,7 +216,7 @@ homepage: https://github.com/indirect/rails3-generators
|
|
212
216
|
licenses: []
|
213
217
|
|
214
218
|
post_install_message: "\n\
|
215
|
-
rails3-generators-0.
|
219
|
+
rails3-generators-0.17.0\n\n\
|
216
220
|
Be sure to check out the wiki, https://wiki.github.com/indirect/rails3-generators/,\n\
|
217
221
|
for information about recent changes to this project.\n\n\
|
218
222
|
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\
|