mongo_db_model 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -28,3 +28,37 @@ Using Mongoid:
28
28
  $ script/generate mongoid:model post name:string
29
29
 
30
30
 
31
+ Executables
32
+ MongoMapper database config
33
+ -----------------
34
+ mongomap_db [database name]
35
+
36
+ $ mongomap_db my_database
37
+
38
+
39
+
40
+ Mongoid database config
41
+ -----------------
42
+ mongoid_db [database name]
43
+
44
+ $ mongoid_db my_database
45
+
46
+
47
+
48
+ Mongoid model
49
+ -----------------
50
+ mongoid_model [model name] [attributes]
51
+
52
+ $ mongoid_model Post name:string expires:date
53
+
54
+
55
+
56
+ MongoMapper model
57
+ -----------------
58
+ mongomap_model [model name] [attributes]
59
+
60
+ $ mongomap_model Post name:string expires:date
61
+
62
+
63
+
64
+
@@ -1,7 +1,6 @@
1
- = mongo_modl
1
+ = Mongo DB generators
2
2
 
3
- Rails 3 generator to generate Mongo DB models.
4
- Includes model generators for Mongo Mapper and Mongoid.
3
+ Rails 3 generators to generate Mongo DB models and database configs for Mongoid and MongoMapper.
5
4
 
6
5
  1. Create new Rails 3 project
7
6
  2. In Gemfile add
@@ -29,9 +28,42 @@ Using Mongoid:
29
28
  b. Generate Mongoid model
30
29
  $ script/generate mongoid:model post name:string
31
30
 
32
- Enjoy :)
31
+ = Executables
33
32
 
34
- == Note on Patches/Pull Requests
33
+ When the gem is installed the followin executables are also installed. You can use the executables globally on your system, in any Ruby or Rails project
34
+ simply by running the executables are demonstrated below.
35
+
36
+ == MongoMapper database config
37
+
38
+ mongomap_db [database name]
39
+
40
+ $ mongomap_db my_database
41
+
42
+
43
+
44
+ == Mongoid database config
45
+
46
+ mongoid_db [database name]
47
+
48
+ $ mongoid_db my_database
49
+
50
+
51
+
52
+ == Mongoid model
53
+
54
+ mongoid_model [model name] [attributes]
55
+
56
+ $ mongoid_model Post name:string expires:date
57
+
58
+
59
+ == MongoMapper model
60
+
61
+ mongomap_model [model name] [attributes]
62
+
63
+ $ mongomap_model Post name:string expires:date
64
+
65
+
66
+ = Note on Patches/Pull Requests
35
67
 
36
68
  * Fork the project.
37
69
  * Make your feature addition or bug fix.
@@ -41,6 +73,6 @@ Enjoy :)
41
73
  (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
74
  * Send me a pull request. Bonus points for topic branches.
43
75
 
44
- == Copyright
76
+ = Copyright
45
77
 
46
78
  Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
@@ -0,0 +1,26 @@
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
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ if %w(--version -v).include? ARGV.first
19
+ puts "Rails #{Rails::VERSION::STRING}"
20
+ exit(0)
21
+ end
22
+
23
+ require 'rails/generators'
24
+ require 'generators/mongoid/database/database_generator'
25
+
26
+ Mongoid::DatabaseGenerator.start
@@ -0,0 +1,28 @@
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
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ if %w(--version -v).include? ARGV.first
19
+ puts "Rails #{Rails::VERSION::STRING}"
20
+ exit(0)
21
+ end
22
+
23
+ ARGV << "--help" if ARGV.empty?
24
+
25
+ require 'rails/generators'
26
+ require 'generators/mongoid/model/model_generator'
27
+
28
+ Mongoid::ModelGenerator.start
@@ -0,0 +1,26 @@
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
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ if %w(--version -v).include? ARGV.first
19
+ puts "Rails #{Rails::VERSION::STRING}"
20
+ exit(0)
21
+ end
22
+
23
+ require 'rails/generators'
24
+ require 'generators/mongo_mapper/database/database_generator'
25
+
26
+ MongoMapper::DatabaseGenerator.start
@@ -0,0 +1,28 @@
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
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ if %w(--version -v).include? ARGV.first
19
+ puts "Rails #{Rails::VERSION::STRING}"
20
+ exit(0)
21
+ end
22
+
23
+ ARGV << "--help" if ARGV.empty?
24
+
25
+ require 'rails/generators'
26
+ require 'generators/mongo_mapper/model/model_generator'
27
+
28
+ MongoMapper::ModelGenerator.start
@@ -0,0 +1,15 @@
1
+ module MongoMapper
2
+ class DatabaseGenerator < Rails::Generators::NamedBase
3
+ argument :database, :type => :string, :default => 'my_db'
4
+
5
+ def self.source_root
6
+ @source_root ||= File.expand_path('../templates', __FILE__)
7
+ end
8
+
9
+ def create_files
10
+ template "mongo_mapper_db_config.rb" , "config/initializers/mongo_mapper_db_config.rb"
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ MongoMapper.database = "<%= database %>-#{Rails.env}"
@@ -0,0 +1,16 @@
1
+ module Mongoid
2
+ class DatabaseGenerator < Rails::Generators::NamedBase
3
+ argument :database, :type => :string, :default => 'my_db'
4
+
5
+ def self.source_root
6
+ @source_root ||= File.expand_path('../templates', __FILE__)
7
+ end
8
+
9
+ def create_files
10
+ template "mongoid.rb" , "config/initializers/mongoid.rb"
11
+ template 'database.mongo.yml', "config/database.mongo.yml"
12
+ end
13
+
14
+ end
15
+ end
16
+ 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
@@ -1,5 +1,8 @@
1
1
  class <%= class_name %>
2
- include Mongoid::Document
2
+ include Mongoid::Document
3
+ include Mongoid::Versioning
4
+ include Mongoid::Timestamps
5
+
3
6
  # Types: Array, Boolean, Date, DateTime, Float, Integer, String, Time and any object that inherits from Mongoid::Document.
4
7
  # Associations: has_one, has_many, belongs_to
5
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_db_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristian Mandrup
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-28 00:00:00 +01:00
13
- default_executable:
12
+ date: 2010-01-29 00:00:00 +01:00
13
+ default_executable: mongomap_model
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -22,10 +22,13 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.2.9
24
24
  version:
25
- description: Rails 3 model generators for Mongo DB
25
+ description: Rails 3 Mongo DB generators for MongoMapper and Mongoid
26
26
  email: kmandrup@gmail.com
27
- executables: []
28
-
27
+ executables:
28
+ - mongoid_db
29
+ - mongoid_model
30
+ - mongomap_db
31
+ - mongomap_model
29
32
  extensions: []
30
33
 
31
34
  extra_rdoc_files:
@@ -33,8 +36,17 @@ extra_rdoc_files:
33
36
  - README
34
37
  - README.rdoc
35
38
  files:
39
+ - bin/mongoid_db
40
+ - bin/mongoid_model
41
+ - bin/mongomap_db
42
+ - bin/mongomap_model
43
+ - lib/generators/mongo_mapper/database/database_generator.rb
44
+ - lib/generators/mongo_mapper/database/templates/mongo_mapper_db_config.rb
36
45
  - lib/generators/mongo_mapper/model/model_generator.rb
37
46
  - lib/generators/mongo_mapper/model/templates/model.rb
47
+ - lib/generators/mongoid/database/database_generator.rb
48
+ - lib/generators/mongoid/database/templates/database.mongo.yml
49
+ - lib/generators/mongoid/database/templates/mongoid.rb
38
50
  - lib/generators/mongoid/model/model_generator.rb
39
51
  - lib/generators/mongoid/model/templates/model.rb
40
52
  - LICENSE
@@ -67,7 +79,7 @@ rubyforge_project:
67
79
  rubygems_version: 1.3.5
68
80
  signing_key:
69
81
  specification_version: 3
70
- summary: Rails 3 model generators for Mongo DB
82
+ summary: Rails 3 generators for Mongo DB
71
83
  test_files:
72
84
  - spec/mongo_modl_spec.rb
73
85
  - spec/spec_helper.rb