mongoid-generator 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,7 +1,26 @@
1
1
  = mongoid-generator
2
2
 
3
+ == Description :
3
4
  A basic mongoid orm generator for rails 3
4
5
 
6
+ == Synopsis :
7
+
8
+ In config/application.rb :
9
+
10
+ config.generators do |g|
11
+ g.orm :mongoid
12
+ g.template_engine :erb
13
+ g.test_framework :test_unit, :fixture => true
14
+ end
15
+
16
+ == Usage :
17
+
18
+ ./script/rails generate model [Model] [field:type,]
19
+
20
+ Options :
21
+ * --timesstamps=[true|false] default true
22
+ * --versionnning=[true|false] default false
23
+
5
24
  == Note on Patches/Pull Requests
6
25
 
7
26
  * Fork the project.
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  gem.email = "guillaume.belleguic@cixi.eu"
11
11
  gem.homepage = "http://github.com/tetsuo692/mongoid-generator"
12
12
  gem.authors = ["guillaume belleguic"]
13
+ gem.add_dependency('rails', "3.0.0.beta")
13
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
15
  end
15
16
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -7,42 +7,42 @@ module Mongoid
7
7
 
8
8
  def self.source_root
9
9
  @_mongoid_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
10
- 'mongoid', generator_name, 'templates'))
10
+ base_name, generator_name, 'templates'))
11
11
  end
12
12
 
13
13
  end
14
-
15
- class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
14
+
15
+ class ActiveModel < ::Rails::Generators::ActiveModel #:nodoc:
16
16
  def self.all(klass)
17
- "#{klass}.all"
17
+ "#{klass}.all"
18
18
  end
19
19
 
20
20
  def self.find(klass, params=nil)
21
- "#{klass}.first(#{params})"
21
+ "#{klass}.find(#{params})"
22
22
  end
23
23
 
24
24
  def self.build(klass, params=nil)
25
- if params
26
- "#{klass}.new(#{params})"
27
- else
28
- "#{klass}.new"
29
- end
25
+ if params
26
+ "#{klass}.new(#{params})"
27
+ else
28
+ "#{klass}.new"
29
+ end
30
30
  end
31
31
 
32
32
  def save
33
- "#{name}.save"
33
+ "#{name}.save"
34
34
  end
35
35
 
36
36
  def update_attributes(params=nil)
37
- "#{name}.update(#{params})"
37
+ "#{name}.update_attributes(#{params})"
38
38
  end
39
39
 
40
40
  def errors
41
- "#{name}.errors"
41
+ "#{name}.errors"
42
42
  end
43
43
 
44
44
  def destroy
45
- "#{name}.destroy"
45
+ "#{name}.destroy"
46
46
  end
47
47
  end
48
48
  end
@@ -52,9 +52,15 @@ module Rails
52
52
  module Generators
53
53
  class GeneratedAttribute #:nodoc:
54
54
  def type_class
55
- return 'DateTime' if type.to_s == 'datetime'
56
- return type.to_s.camelcase
55
+ case type
56
+ when :datetime
57
+ "Time"
58
+ when :text
59
+ "String"
60
+ else
61
+ type.to_s.camelcase
62
+ end
57
63
  end
58
64
  end
59
65
  end
60
- end
66
+ end
@@ -1,14 +1,15 @@
1
1
  class <%= class_name %><%= "< #{options[:parent].classify}" if options[:parent] %>
2
+
2
3
  <% unless options[:parent] -%>
3
4
  include Mongoid::Document
4
- <% if options[:timestamps] %>
5
- include Mongoid::Timestamps
6
- <% end %>
7
- <% if options[:versioning] %>
8
- include Mongoid::Versioning
9
- <% end %>
5
+ <%= 'include Mongoid::Timestamps' if options[:timestamps] %>
6
+ <%= 'include Mongoid::Versioning' if options[:versioning] %>
10
7
  <% end -%>
11
- <% attributes.each do |attribute| -%>
8
+
9
+ <% attributes.reject{|attr| attr.reference?}.each do |attribute| -%>
12
10
  field :<%= attribute.name %>, :type => <%= attribute.type_class %>
13
11
  <% end -%>
12
+ <% attributes.select{|attr| attr.reference? }.each do |attribute| -%>
13
+ belongs_to :<%= attribute.name%>, :inverse_of => :<%= class_name.tableize %>
14
+ <% end -%>
14
15
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid-generator}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["guillaume belleguic"]
12
- s.date = %q{2010-04-02}
12
+ s.date = %q{2010-04-07}
13
13
  s.description = %q{Mongoid orm generator for rails 3}
14
14
  s.email = %q{guillaume.belleguic@cixi.eu}
15
15
  s.extra_rdoc_files = [
@@ -46,9 +46,12 @@ Gem::Specification.new do |s|
46
46
  s.specification_version = 3
47
47
 
48
48
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<rails>, ["= 3.0.0.beta"])
49
50
  else
51
+ s.add_dependency(%q<rails>, ["= 3.0.0.beta"])
50
52
  end
51
53
  else
54
+ s.add_dependency(%q<rails>, ["= 3.0.0.beta"])
52
55
  end
53
56
  end
54
57
 
data/test/helper.rb CHANGED
@@ -1,9 +1,3 @@
1
- require 'rubygems'
2
1
  require 'test/unit'
3
-
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- require 'mongoid-generator'
7
-
8
- class Test::Unit::TestCase
9
- end
2
+ require 'rubygems'
3
+ require 'rails/generators'
@@ -1,7 +1,19 @@
1
1
  require 'helper'
2
+ require 'generators/mongoid/model/model_generator'
2
3
 
3
- class TestMongoidGenerator < Test::Unit::TestCase
4
- def test_something_for_real
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ class MongoidGeneratorTest < Test::Unit::TestCase
5
+ def setup
6
+ @destination = File.join('tmp', 'test_app')
7
+ @source = Mongoid::Generators::ModelGenerator.source_root
8
+
9
+ Mongoid::Generators::ModelGenerator.start(['Account'], :destination => @source)
6
10
  end
7
- end
11
+
12
+ def teardown
13
+ FileUtils.rm_rf(@destination)
14
+ end
15
+
16
+ def test_first_test
17
+ assert File.exists?(File.join(@destination, 'app', 'model', 'account.rb'))
18
+ end
19
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
7
  - 1
9
- version: 0.0.1
8
+ - 0
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - guillaume belleguic
@@ -14,10 +14,24 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-02 00:00:00 +02:00
17
+ date: 2010-04-07 00:00:00 +02:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 0
31
+ - beta
32
+ version: 3.0.0.beta
33
+ type: :runtime
34
+ version_requirements: *id001
21
35
  description: Mongoid orm generator for rails 3
22
36
  email: guillaume.belleguic@cixi.eu
23
37
  executables: []