mongo_db_gen 0.3.3

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/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,39 @@
1
+ Mongo DB generators
2
+ ===================
3
+ The Mongo DB Rails 3 generators includes the following generators:
4
+
5
+ Mongoid
6
+ -------
7
+ * mongoid:setup - setup Rails app to use Mongoid
8
+ * mongoid:model - generates a Mongoid model
9
+
10
+ Example Use:
11
+
12
+ Setup use of Mongoid
13
+
14
+ rails g mongoid:setup
15
+
16
+ Create new model Person with name attribute
17
+
18
+ rails g mongoid:model person name:string
19
+
20
+ Mongo Mapper
21
+ ------------
22
+
23
+ * mongo_mapper:setup - setup Rails app to use Mongo Mapper
24
+ * mongo_mapper:model - generates a Mongo Mapper model
25
+
26
+ Example Use:
27
+
28
+ Setup use of Mongo Mapper
29
+
30
+ rails g mongoid:setup
31
+
32
+ Create new Mongo Mapper model Person with name attribute
33
+
34
+ rails g mongoid:model person name:string
35
+
36
+ Notice
37
+ ======
38
+ This is currently a work in progress. Please feel free to join in the effort and fork this project and fix whatever bugs etc.
39
+
@@ -0,0 +1,38 @@
1
+ = Mongo DB generators
2
+
3
+ The Mongo DB Rails 3 generators includes the following generators:
4
+
5
+ == Mongoid
6
+
7
+ * mongoid:setup - setup Rails app to use Mongoid
8
+ * mongoid:model - generates a Mongoid model
9
+
10
+ Example Use:
11
+
12
+ Setup use of Mongoid
13
+
14
+ rails g mongoid:setup
15
+
16
+ Create new model Person with name attribute
17
+
18
+ rails g mongoid:model person name:string
19
+
20
+ == Mongo Mapper
21
+
22
+ * mongo_mapper:setup - setup Rails app to use Mongo Mapper
23
+ * mongo_mapper:model - generates a Mongo Mapper model
24
+
25
+ Example Use:
26
+
27
+ Setup use of Mongo Mapper
28
+
29
+ rails g mongoid:setup
30
+
31
+ Create new Mongo Mapper model Person with name attribute
32
+
33
+ rails g mongoid:model person name:string
34
+
35
+ = Notice
36
+
37
+ This is currently a work in progress. Please feel free to join in the effort and fork this project and fix whatever bugs etc.
38
+
@@ -0,0 +1,21 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ end
13
+
14
+ Signal.trap("INT") { puts; exit }
15
+
16
+ ARGV << "--help" if ARGV.empty?
17
+
18
+ require 'rails/generators'
19
+ require 'generators/mongoid/model/model_generator'
20
+
21
+ Mongoid::Generators::ModelGenerator.start
@@ -0,0 +1,19 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ end
13
+
14
+ Signal.trap("INT") { puts; exit }
15
+
16
+ require 'rails/generators'
17
+ require 'generators/mongoid/setup/setup_generator'
18
+
19
+ Mongoid::Generators::SetupGenerator.start
@@ -0,0 +1,21 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ end
13
+
14
+ Signal.trap("INT") { puts; exit }
15
+
16
+ ARGV << "--help" if ARGV.empty?
17
+
18
+ require 'rails/generators'
19
+ require 'generators/mongo_mapper/model/model_generator'
20
+
21
+ MongoMapper::Generators::ModelGenerator.start
@@ -0,0 +1,19 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ end
13
+
14
+ Signal.trap("INT") { puts; exit }
15
+
16
+ require 'rails/generators'
17
+ require 'generators/mongo_mapper/setup/setup_generator'
18
+
19
+ MongoMapper::Generators::SetupGenerator.start
@@ -0,0 +1,15 @@
1
+ require 'thor-ext'
2
+
3
+ module MongoDatabase
4
+ module Generators
5
+ module Base
6
+ include ThorExtensions
7
+
8
+ def configure_gems
9
+ cleanup_gemfile
10
+ add_gems(%w{mongo mongo-ext mongoid})
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,22 @@
1
+ module MongoMapper
2
+ module Generators
3
+ class ModelGenerator < Rails::Generators::NamedBase
4
+
5
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
6
+
7
+ def self.source_root
8
+ @source_root ||= File.expand_path('../templates', __FILE__)
9
+ end
10
+
11
+ def self.banner
12
+ "#{$0} mongo_mapper:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
13
+ end
14
+
15
+ def create_model_file
16
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
17
+ end
18
+
19
+ # hook_for :test
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ require 'generators/mongo_db_base'
2
+
3
+ module MongoMapper
4
+ module Generators
5
+ class SetupGenerator < Rails::Generators::Base
6
+ include MongoDatabase::Generators::Base
7
+
8
+ argument :database, :type => :string, :default => 'mongo_db_default'
9
+
10
+ def self.source_root
11
+ @source_root ||= File.expand_path('../templates', __FILE__)
12
+ end
13
+
14
+ def self.banner
15
+ "#{$0} mongo_mapper:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
16
+ end
17
+
18
+ def configure_gems
19
+ add_gems %w{mongo_ext mongo mongo_mapper}
20
+ end
21
+
22
+ def create_files
23
+ template "mongo_mapper_db_config.rb" , "config/initializers/mongo_mapper_db_config.rb"
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1 @@
1
+ MongoMapper.database = "<%= database %>-#{Rails.env}"
@@ -0,0 +1,21 @@
1
+ module Mongoid
2
+ module Generators
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 self.banner
11
+ "#{$0} mongoid:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
12
+ end
13
+
14
+ def create_model_file
15
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
16
+ end
17
+
18
+ # hook_for :test
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ require 'generators/mongo_db_base'
2
+
3
+ module Mongoid
4
+ module Generators
5
+ class SetupGenerator < Rails::Generators::Base
6
+ include MongoDatabase::Generators::Base
7
+
8
+ argument :database, :type => :string, :default => 'mongo_db_default'
9
+
10
+ def self.source_root
11
+ @source_root ||= File.expand_path('../templates', __FILE__)
12
+ end
13
+
14
+ def self.banner
15
+ "#{$0} mongoid:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
16
+ end
17
+
18
+ def configure_gems
19
+ add_gems %w{mongo_ext mongo mongoid}
20
+ end
21
+
22
+ def create_files
23
+ template "mongoid.rb" , "config/initializers/mongoid.rb"
24
+ template 'database.mongo.yml', "config/database.mongo.yml"
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ defaults: &defaults
2
+ host: localhost
3
+
4
+ development:
5
+ <<: *defaults
6
+ database: <%= database %>
7
+
8
+ production:
9
+ <<: *defaults
10
+ host: test
11
+ username: user
12
+ password: pass
13
+ database: <%= database %>
@@ -0,0 +1,8 @@
1
+ File.open(File.join(Rails.root, 'config/database.mongo.yml'), 'r') do |f|
2
+ @settings = YAML.load(f)[RAILS_ENV]
3
+ end
4
+ connection = Mongo::Connection.new(@settings["host"])
5
+ Mongoid.database = connection.db(@settings["database"])
6
+ if @settings["username"]
7
+ Mongoid.database.authenticate(@settings["username"], @settings["password"])
8
+ 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,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_db_gen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ platform: ruby
6
+ authors:
7
+ - Kristian Mandrup
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-07 00:00:00 +01:00
13
+ default_executable: mongomap_model
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
+ - !ruby/object:Gem::Dependency
26
+ name: thor-ext
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Rails 3 Mongo DB generators for MongoMapper and Mongoid
36
+ email: kmandrup@gmail.com
37
+ executables:
38
+ - mongoid_setup
39
+ - mongoid_model
40
+ - mongomapper_setup
41
+ - mongomapper_model
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - LICENSE
46
+ - README
47
+ - README.rdoc
48
+ files:
49
+ - bin/mongoid_model
50
+ - bin/mongoid_setup
51
+ - bin/mongomapper_model
52
+ - bin/mongomapper_setup
53
+ - lib/generators/mongo_db_base.rb
54
+ - lib/generators/mongo_mapper/model/model_generator.rb
55
+ - lib/generators/mongo_mapper/setup/setup_generator.rb
56
+ - lib/generators/mongo_mapper/setup/templates/mongo_mapper_db_config.rb
57
+ - lib/generators/mongoid/model/model_generator.rb
58
+ - lib/generators/mongoid/setup/setup_generator.rb
59
+ - lib/generators/mongoid/setup/templates/database.mongo.yml
60
+ - lib/generators/mongoid/setup/templates/mongoid.rb
61
+ - LICENSE
62
+ - README
63
+ - README.rdoc
64
+ has_rdoc: true
65
+ homepage: http://github.com/kristianmandrup/mongo_modl
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --charset=UTF-8
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.5
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Rails 3 generators for Mongo DB
92
+ test_files:
93
+ - spec/spec_helper.rb