smart_model 0.1.0

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
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.rdoc ADDED
@@ -0,0 +1,59 @@
1
+ = SmartModel
2
+ == What is
3
+ SmartModel is a rails 3 library made to improve the way you use MongoMapper. It gives you aliases, and even a model generator for mongoDB models.
4
+
5
+ == Setup
6
+ === As plugin
7
+ To setup SmartMongo as a plugin , you need mongo_mapper(that needs bson_ext) , so add this to your Gemfile
8
+ gem 'mongo_mapper'
9
+ gem 'bson_ext'
10
+ And then run
11
+ rails plugin install http://github.com/nathanPro/SmartModel.git
12
+ === As a gem
13
+ Just add
14
+ gem 'smart_model'
15
+ To your Gemfile and run
16
+ [sudo] bundle install
17
+ And everything is OK!
18
+
19
+ == Generator
20
+ SmartModel gives you a model generator:
21
+ === smart_model
22
+ rails g smart_model project name:string content:string created_at:date in_progress:done
23
+ That creates a model Project inherited from SmartMongo::Base
24
+
25
+ == SmartModel::Base
26
+ Is a class with all the MongoMapper::Document methods, that even gives you aliases for setting your database up
27
+ === Managing columns
28
+ To add a title columns to your project model, that keeps a string , you can just type this:
29
+ class Project
30
+ include SmartModel::Base # Load SmartModel
31
+ string :title , :required => true # Create title column ,that accept strings
32
+ end
33
+ Or if you have many columns with the same behaviour , you can just manage them just like this:
34
+ class Project
35
+ include SmartModel::Base
36
+ strings [:title , : content] , :required => true # Create :title and :content columns
37
+ end
38
+ The given methods are
39
+ string(s) , integer(s) , boolean(s) , array(s) , objectid(s) , date(s) , time(s)
40
+ === Relationships
41
+ With SmartModel::Base you can just do this :
42
+ class Task
43
+ include SmartModel::Base
44
+ strings [ :name , :description ]
45
+ boolean :done
46
+ belongs_to :project
47
+ end
48
+ That SmartModel already creates the db column and stablish the relationship.
49
+
50
+ == TO-DO
51
+ create a scaffold generator ;
52
+ make the tests *test something*
53
+
54
+ == Why have I done it?
55
+ I was on vacation , so , I decided to code something usefull , and this was my first idea
56
+
57
+ == License
58
+ Read under the amazing MIT license
59
+
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Create rails files for model generator, using MongoMapper and SmartMongo.
3
+
4
+ Example:
5
+ rails generate smart_model Thing
6
+
7
+ This will create:
8
+ app/models/thing.rb
9
+ test/unit/thing_test.rb
10
+ test/fixtures/things.yml
11
+
@@ -0,0 +1,15 @@
1
+ class SmartModelGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ argument :name , :type => :string
4
+ argument :db_fields, :type => :hash
5
+ def create_model
6
+ template "model.rb" , "app/models/#{file_name}.rb"
7
+ template "test.rb" , "test/unit/#{file_name}_test.rb"
8
+ copy_file "fixture.yml" , "test/fixtures/#{file_name.pluralize}.yml"
9
+ end
10
+ private
11
+ def file_name
12
+ name.downcase
13
+ end
14
+ end
15
+
@@ -0,0 +1,12 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ # This model initially had no columns defined. If you add columns to the
4
+ # model remove the '{}' from the fixture names and add the columns immediately
5
+ # below each fixture, per the syntax in the comments below
6
+ #
7
+ one: {}
8
+ # column: value
9
+ #
10
+ two: {}
11
+ # column: value
12
+
@@ -0,0 +1,7 @@
1
+ class <%= file_name.camelcase %>
2
+ include SmartModel::Base
3
+ <%- db_fields.each do |key,value| -%>
4
+ <%= value %> :<%= key %>
5
+ <%- end -%>
6
+ end
7
+
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class <%= file_name.capitalize %>Test < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
9
+
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'mongo_mapper'
3
+
4
+ module SmartModel
5
+ module Base
6
+ def self.included(model)
7
+ # include MongoMapper::Document
8
+ model.send :include, MongoMapper::Document
9
+ # create database columns methods
10
+ %w(String Integer Boolean Array ObjectId Date Time).each do |name|
11
+ model.class_eval "
12
+ private
13
+ def self.#{name.downcase}(value , options = {})
14
+ key value , #{name}, options
15
+ end
16
+
17
+ def self.#{name.downcase.pluralize}(values , options = {})
18
+ values.each do |val|
19
+ key val , #{name} , options
20
+ end
21
+ end
22
+ "
23
+ end
24
+ # create column in the db with relationship belongs_to
25
+ model.class_eval "
26
+ def self.belongs_to(value)
27
+ key \"\#{value}_id\".to_sym , ObjectId
28
+ super value
29
+ end"
30
+ end
31
+ end
32
+ end
33
+
data/rails/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Include hook code here
2
+ require File.join(File.dirname(__FILE__), "..", "lib", "smart_model")
3
+
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class SmartModelTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
9
+
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_model
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - "Nathan Proen\xC3\xA7a"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-27 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: -462942284
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0beta4
34
+ version: 3.0.0beta4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: mongo_mapper
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 59
46
+ segments:
47
+ - 0
48
+ - 8
49
+ - 2
50
+ version: 0.8.2
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: bson_ext
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 21
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 1
66
+ version: 1.0.1
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: Gives you support to use MongoDB and MongoMapper
70
+ email: nathan@vieiraproenca.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files: []
76
+
77
+ files:
78
+ - lib/generators/smart_model/templates/model.rb
79
+ - lib/generators/smart_model/templates/fixture.yml
80
+ - lib/generators/smart_model/templates/test.rb
81
+ - lib/generators/smart_model/USAGE
82
+ - lib/generators/smart_model/smart_model_generator.rb
83
+ - lib/smart_model.rb
84
+ - test/smart_model_test.rb
85
+ - test/test_helper.rb
86
+ - rails/init.rb
87
+ - MIT-LICENSE
88
+ - README.rdoc
89
+ has_rdoc: true
90
+ homepage: http://github.com/nathanpro/smartmodel
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options: []
95
+
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project:
119
+ rubygems_version: 1.3.7
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Use all the power of MongoDB
123
+ test_files: []
124
+