model_mill 0.1.1 → 0.2.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/VERSION +1 -1
- data/lib/generators/model_mill/models/models_generator.rb +9 -9
- data/lib/generators/model_mill/models/templates/base.rb +2 -2
- data/lib/generators/model_mill/models/templates/model.rb +1 -1
- data/model_mill.gemspec +1 -1
- data/spec/generators/model_generator_spec.rb +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -3,33 +3,33 @@ module ModelMill
|
|
3
3
|
class ModelsGenerator < Rails::Generators::Base
|
4
4
|
source_root File.expand_path('../templates', __FILE__)
|
5
5
|
|
6
|
-
|
7
|
-
argument :excludes, :type => :array, :required => false, :default => []
|
6
|
+
class_option :namespace, :type => :string, :required => false, :default => nil
|
7
|
+
#argument :excludes, :type => :array, :required => false, :default => []
|
8
8
|
|
9
9
|
def generate_models
|
10
|
-
if namespace
|
11
|
-
empty_directory("app/models/#{namespace.downcase}")
|
10
|
+
if options[:namespace]
|
11
|
+
empty_directory("app/models/#{options[:namespace].downcase}")
|
12
12
|
generate_base_namespaced_model
|
13
13
|
end
|
14
14
|
discovered_tables.each do |table_name|
|
15
15
|
@model_name = model_name_from_table_name table_name
|
16
16
|
@model_file_name = model_file_name_from_table_name table_name
|
17
|
-
template 'model.rb', "app/models/#{namespace ? namespace+'/' : ''}#{@model_file_name}.rb"
|
17
|
+
template 'model.rb', "app/models/#{options[:namespace] ? options[:namespace]+'/' : ''}#{@model_file_name}.rb"
|
18
18
|
end
|
19
|
-
puts %Q(config.autoload_paths += %W(\#{config.root}/app/models/#{namespace.downcase})) if namespace
|
19
|
+
puts %Q(config.autoload_paths += %W(\#{config.root}/app/models/#{options[:namespace].downcase})) if options[:namespace]
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
def connection
|
24
|
-
@conn ||= namespace ? Kernel.const_get(namespace.camelize)::Base.connection : ActiveRecord::Base.connection
|
24
|
+
@conn ||= options[:namespace] ? Kernel.const_get(options[:namespace].camelize)::Base.connection : ActiveRecord::Base.connection
|
25
25
|
end
|
26
26
|
|
27
27
|
def connection_info
|
28
|
-
YAML.load(ERB.new(File.read(File.expand_path(File.join("config","database.yml")))))[namespace.downcase]
|
28
|
+
YAML.load(ERB.new(File.read(File.expand_path(File.join("config","database.yml")))))[options[:namespace].downcase]
|
29
29
|
end
|
30
30
|
|
31
31
|
def generate_base_namespaced_model
|
32
|
-
template 'base.rb', "app/models/#{namespace}/base.rb"
|
32
|
+
template 'base.rb', "app/models/#{options[:namespace]}/base.rb"
|
33
33
|
end
|
34
34
|
|
35
35
|
def discovered_tables
|
@@ -1,3 +1,3 @@
|
|
1
|
-
class <%= namespace ? namespace.camelize + '::' : '' %><%= @model_name %> < <%= namespace ? namespace.camelize : 'ActiveRecord' %>::Base
|
1
|
+
class <%= options[:namespace] ? options[:namespace].camelize + '::' : '' %><%= @model_name %> < <%= options[:namespace] ? options[:namespace].camelize : 'ActiveRecord' %>::Base
|
2
2
|
end
|
3
3
|
|
data/model_mill.gemspec
CHANGED
@@ -42,7 +42,7 @@ describe 'models_generator' do
|
|
42
42
|
|
43
43
|
it "generates a base model for the namespace" do
|
44
44
|
GeneratorSpec.with_generator do |g|
|
45
|
-
g.run_generator @namespace
|
45
|
+
g.run_generator [ "--namespace=#{@namespace}" ]
|
46
46
|
g.should generate_file("app/models/#{@namespace}")
|
47
47
|
g.should generate_file("app/models/#{@namespace}/base.rb")
|
48
48
|
file_contents("app/models/#{@namespace}/base.rb").should match(/class #{@namespace.camelize}::Base < ActiveRecord::Base/)
|
@@ -51,7 +51,7 @@ describe 'models_generator' do
|
|
51
51
|
|
52
52
|
it "generates a model for each table" do
|
53
53
|
GeneratorSpec.with_generator do |g|
|
54
|
-
g.run_generator @namespace
|
54
|
+
g.run_generator [ "--namespace=#{@namespace}" ]
|
55
55
|
@tables.each do |tn|
|
56
56
|
g.should generate_file("app/models/#{@namespace}/#{tn.singularize.underscore}.rb")
|
57
57
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_mill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joe Martinez
|