mongo_db_model 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kristian Mandrup
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,30 @@
1
+ Rails 3 generator to generate Mongo DB models.
2
+ Includes model generators for Mongo Mapper and Mongoid.
3
+
4
+ 1. Create new Rails 3 project
5
+ 2. In Gemfile add
6
+ gem 'mongo_db_model'
7
+ 3. In console run
8
+ $ gem bundle
9
+
10
+ Using Mongo Mapper:
11
+ a. To set application ORM to Mongo Mapper:
12
+ # config/application.rb
13
+ config.generators do |g|
14
+ g.orm :mongo_mapper
15
+ end
16
+
17
+ b. Generate Mongo Mapper model
18
+ $ script/generate mongo_mapper:model post name:string
19
+
20
+
21
+ Using Mongoid:
22
+ a. To set application ORM to Mongoid
23
+ # config/application.rb
24
+ config.generators do |g|
25
+ g.orm :mongoid
26
+ end
27
+ b. Generate Mongoid model
28
+ $ script/generate mongoid:model post name:string
29
+
30
+
@@ -0,0 +1,46 @@
1
+ = mongo_modl
2
+
3
+ Rails 3 generator to generate Mongo DB models.
4
+ Includes model generators for Mongo Mapper and Mongoid.
5
+
6
+ 1. Create new Rails 3 project
7
+ 2. In Gemfile add
8
+ gem 'mongo_db_model'
9
+ 3. In console run
10
+ $ gem bundle
11
+
12
+ Using Mongo Mapper:
13
+ a. To set application ORM to Mongo Mapper:
14
+ # config/application.rb
15
+ config.generators do |g|
16
+ g.orm :mongo_mapper
17
+ end
18
+
19
+ b. Generate Mongo Mapper model
20
+ $ script/generate mongo_mapper:model post name:string
21
+
22
+
23
+ Using Mongoid:
24
+ a. To set application ORM to Mongoid
25
+ # config/application.rb
26
+ config.generators do |g|
27
+ g.orm :mongoid
28
+ end
29
+ b. Generate Mongoid model
30
+ $ script/generate mongoid:model post name:string
31
+
32
+ Enjoy :)
33
+
34
+ == Note on Patches/Pull Requests
35
+
36
+ * Fork the project.
37
+ * Make your feature addition or bug fix.
38
+ * Add tests for it. This is important so I don't break it in a
39
+ future version unintentionally.
40
+ * Commit, do not mess with rakefile, version, or history.
41
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
42
+ * Send me a pull request. Bonus points for topic branches.
43
+
44
+ == Copyright
45
+
46
+ Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
@@ -0,0 +1,17 @@
1
+ module MongoMapper
2
+
3
+ class ModelGenerator < Rails::Generators::NamedBase
4
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
5
+
6
+ def self.source_root
7
+ @source_root ||= File.expand_path('../templates', __FILE__)
8
+ end
9
+
10
+ def create_model_file
11
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
12
+ end
13
+
14
+ # hook_for :test_framework
15
+ end
16
+
17
+ end
@@ -0,0 +1,7 @@
1
+ class <%= class_name %>
2
+ include MongoMapper::Document
3
+
4
+ <% for attribute in attributes -%>
5
+ key :<%= attribute.name %>, <%= attribute.type %>
6
+ <% end -%>
7
+ end
@@ -0,0 +1,17 @@
1
+ module Mongoid
2
+
3
+ class ModelGenerator < Rails::Generators::NamedBase
4
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
5
+
6
+ def self.source_root
7
+ @source_root ||= File.expand_path('../templates', __FILE__)
8
+ end
9
+
10
+ def create_model_file
11
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
12
+ end
13
+
14
+ # hook_for :test_framework
15
+ end
16
+
17
+ end
@@ -0,0 +1,9 @@
1
+ class <%= class_name %>
2
+ include Mongoid::Document
3
+ # Types: Array, Boolean, Date, DateTime, Float, Integer, String, Time and any object that inherits from Mongoid::Document.
4
+ # Associations: has_one, has_many, belongs_to
5
+
6
+ <% for attribute in attributes -%>
7
+ field :<%= attribute.name %>, :type => <%= attribute.type %>
8
+ <% end -%>
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "MongoModl" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'mongo_modl'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_db_model
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Kristian Mandrup
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-28 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ description: Rails 3 model generators for Mongo DB
26
+ email: kmandrup@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README
34
+ - README.rdoc
35
+ files:
36
+ - lib/generators/mongo_mapper/model/model_generator.rb
37
+ - lib/generators/mongo_mapper/model/templates/model.rb
38
+ - lib/generators/mongoid/model/model_generator.rb
39
+ - lib/generators/mongoid/model/templates/model.rb
40
+ - LICENSE
41
+ - README
42
+ - README.rdoc
43
+ has_rdoc: true
44
+ homepage: http://github.com/kristianmandrup/mongo_modl
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Rails 3 model generators for Mongo DB
71
+ test_files:
72
+ - spec/mongo_modl_spec.rb
73
+ - spec/spec_helper.rb