model_mill 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
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
- argument :namespace, :type => :string, :required => false, :default => nil
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,5 +1,5 @@
1
- class <%= namespace.camelize %>::Base < ActiveRecord::Base
1
+ class <%= options[:namespace].camelize %>::Base < ActiveRecord::Base
2
2
  self.abstract_class = true
3
- establish_connection "<%= namespace %>"
3
+ establish_connection "<%= options[:namespace] %>"
4
4
  end
5
5
 
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{model_mill}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joe Martinez"]
@@ -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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joe Martinez