merb_mongoid 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/Generators ADDED
@@ -0,0 +1,4 @@
1
+ scope 'merb-gen' do
2
+ dir = File.join(File.dirname(__FILE__), 'lib', 'generators/')
3
+ Merb.add_generators dir + 'model', dir + 'resource_controller'
4
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jordan Bracco
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,18 @@
1
+ = merb_mongoid
2
+
3
+ A plugin for the Merb framework that provides support for MongoID Models.
4
+
5
+ == Connection options
6
+
7
+ Merb MongoID plugin uses config/database.yml for connection configuration.
8
+
9
+ Options are:
10
+
11
+ - `host` provide a string or an array of strings to attempt connections with
12
+ - `database`
13
+
14
+ It's more or less than a copy/paste for MongoID of shingara/merb_mongomapper.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2010 Jordan Bracco. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "merb_mongoid"
8
+ gem.summary = %Q{A plugin for the Merb framework that provides support for MongoID Models.}
9
+ gem.description = %Q{A plugin for the Merb framework that provides support for MongoID Models.}
10
+ gem.email = "code@webs.ly"
11
+ gem.homepage = "http://github.com/webs/merb_mongoid"
12
+ gem.authors = ["Jordan Bracco"]
13
+ gem.add_dependency('merb-core', '>= 1.0.9')
14
+ gem.add_dependency("mongoid", ">= 1.0.5")
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,4 @@
1
+ Merb::Generators::ModelGenerator.template :model_mongoid, :orm => :mongoid do |t|
2
+ t.source = File.dirname(__FILE__) / "templates/model/app/models/%file_name%.rb"
3
+ t.destination = "app/models" / base_path / "#{file_name}.rb"
4
+ end
@@ -0,0 +1,12 @@
1
+ Merb::Generators::ResourceControllerGenerator.template :controller_mongoid, :orm => :mongoid do |t|
2
+ t.source = File.dirname(__FILE__) / "templates/resource_controller/app/controllers/%file_name%.rb"
3
+ t.destination = "app/controllers" / base_path / "#{file_name}.rb"
4
+ end
5
+
6
+ [:index, :show, :edit, :new].each do |view|
7
+ Merb::Generators::ResourceControllerGenerator.template "view_#{view}_mongoid".to_sym,
8
+ :orm => :mongoid, :template_engine => :erb do |t|
9
+ t.source = File.dirname(__FILE__) / "templates/resource_controller/app/views/%file_name%/#{view}.html.erb"
10
+ t.destination = "app/views" / base_path / "#{file_name}/#{view}.html.erb"
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %>
3
+ include Mongoid::Document
4
+ #include Mongoid::Timestamps
5
+ end
6
+ <% end -%>
@@ -0,0 +1,66 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %> < Application
3
+ # provides :xml, :yaml, :js
4
+
5
+ # GET /<%= resource_path %>
6
+ def index
7
+ @<%= plural_model %> = <%= model_class_name %>.all
8
+ display @<%= plural_model %>
9
+ end
10
+
11
+ # GET /<%= resource_path %>/:id
12
+ def show
13
+ @<%= singular_model %> = <%= model_class_name %>.find(params[:id])
14
+ raise NotFound unless @<%= singular_model %>
15
+ display @<%= singular_model %>
16
+ end
17
+
18
+ # GET /<%= resource_path %>/new
19
+ def new
20
+ only_provides :html
21
+ @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
22
+ render
23
+ end
24
+
25
+ # POST /<%= resource_path %>
26
+ def create
27
+ @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
28
+ if @<%= singular_model %>.save
29
+ redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
30
+ else
31
+ render :new
32
+ end
33
+ end
34
+
35
+ # GET /<%= resource_path %>/:id/edit
36
+ def edit
37
+ only_provides :html
38
+ @<%= singular_model %> = <%= model_class_name %>.find(params[:id])
39
+ raise NotFound unless @<%= singular_model %>
40
+ render
41
+ end
42
+
43
+ # PUT /<%= resource_path %>/:id
44
+ def update
45
+ @<%= singular_model %> = <%= model_class_name %>.find(params[:id])
46
+ raise NotFound unless @<%= singular_model %>
47
+ if @<%= singular_model %>.update(params[:<%= singular_model %>])
48
+ redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
49
+ else
50
+ raise BadRequest
51
+ end
52
+ end
53
+
54
+ # DELETE /<%= resource_path %>/:id
55
+ def destroy
56
+ @<%= singular_model %> = <%= model_class_name %>.find(params[:id])
57
+ raise NotFound unless @<%= singular_model %>
58
+ if @<%= singular_model %>.destroy
59
+ redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>s)
60
+ else
61
+ raise BadRequest
62
+ end
63
+ end
64
+
65
+ end
66
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, edit action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/edit.html.erb</tt></p>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, index action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/index.html.erb</tt></p>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, new action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/new.html.erb</tt></p>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, show action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/show.html.erb</tt></p>
@@ -0,0 +1,66 @@
1
+ require "fileutils"
2
+ require "mongoid"
3
+
4
+ module Merb
5
+ module Orms
6
+ module Mongoid
7
+
8
+ class << self
9
+
10
+ def config_file() Merb.dir_for(:config) / "database.yml" end
11
+ def sample_dest() Merb.dir_for(:config) / "database.yml.sample" end
12
+ def sample_source() File.dirname(__FILE__) / "database.yml.sample" end
13
+
14
+ def copy_sample_config
15
+ FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
16
+ end
17
+
18
+ def get_config
19
+ # Convert string keys to symbols
20
+ full_config = Erubis.load_yaml_file(config_file)
21
+ config = (Merb::Plugins.config[:merb_mongoid] = {})
22
+ (full_config[Merb.environment.to_sym] || full_config[Merb.environment] || full_config[:development]).each do |key, value|
23
+ config[key.to_sym] = value
24
+ end
25
+ config
26
+ end
27
+
28
+ def config
29
+ @config ||= get_config
30
+ end
31
+
32
+ def connect
33
+ no_database_file unless File.exists?(config_file)
34
+
35
+ # it is possible that we have been passed an array of hosts - attempt each in turn until one is found
36
+ host = config[:host] || 'localhost'
37
+ port = config[:port] || 27017
38
+ begin
39
+ Merb.logger.info!("Attempting connection to the '#{config[:database]}' database on '#{host}' ...")
40
+ connection = ::Mongo::Connection.new(host, port)
41
+ ::Mongoid.database = connection.db(config[:database])
42
+ if config[:username]
43
+ ::Mongoid.database.authenticate(config[:username], config[:password])
44
+ end
45
+ Merb.logger.info!("Connected to '#{host}'")
46
+ return true
47
+ rescue Errno::ECONNREFUSED
48
+ Merb.logger.info!("#{host} not available")
49
+ rescue => e
50
+ Merb.logger.info!("Connection Error: #{e}")
51
+ Merb.print_colorized_backtrace(e)
52
+ exit(1)
53
+ end
54
+ end
55
+
56
+ def no_database_file
57
+ copy_sample_config
58
+ Merb.logger.set_log(STDERR)
59
+ Merb.logger.error! "No database.yml file found at #{config_file}."
60
+ Merb.logger.error! "A sample file was created called #{sample_dest} for you to copy and edit."
61
+ exit(1)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,13 @@
1
+ defaults: &defaults
2
+ host: localhost
3
+
4
+ development:
5
+ <<: *defaults
6
+ database: fanboy_dev
7
+
8
+ production:
9
+ <<: *defaults
10
+ host: db.mongohq.com
11
+ username: user
12
+ password: pass
13
+ database: fanboy
@@ -0,0 +1,18 @@
1
+ # make sure we're running inside Merb
2
+ if defined?(Merb::Plugins)
3
+
4
+ # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
5
+ Merb::Plugins.config[:merb_mongoid] = {}
6
+ require File.join(File.dirname(__FILE__) / "merb" / "orms" / "mongoid" / "connection" )
7
+
8
+
9
+ class Merb::Orms::Mongoid::Connect < Merb::BootLoader
10
+ after BeforeAppLoads
11
+
12
+ def self.run
13
+ Merb::Orms::Mongoid.connect
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{merb_mongoid}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jordan Bracco"]
12
+ s.date = %q{2010-01-14}
13
+ s.description = %q{A plugin for the Merb framework that provides support for MongoID Models.}
14
+ s.email = %q{code@webs.ly}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "Generators",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/generators/model.rb",
28
+ "lib/generators/resource_controller.rb",
29
+ "lib/generators/templates/model/app/models/%file_name%.rb",
30
+ "lib/generators/templates/resource_controller/app/controllers/%file_name%.rb",
31
+ "lib/generators/templates/resource_controller/app/views/%file_name%/edit.html.erb",
32
+ "lib/generators/templates/resource_controller/app/views/%file_name%/index.html.erb",
33
+ "lib/generators/templates/resource_controller/app/views/%file_name%/new.html.erb",
34
+ "lib/generators/templates/resource_controller/app/views/%file_name%/show.html.erb",
35
+ "lib/merb/orms/mongoid/connection.rb",
36
+ "lib/merb/orms/mongoid/database.yml.sample",
37
+ "lib/merb_mongoid.rb",
38
+ "merb_mongoid.gemspec",
39
+ "test/helper.rb",
40
+ "test/test_merb_mongoid.rb"
41
+ ]
42
+ s.homepage = %q{http://github.com/webs/merb_mongoid}
43
+ s.rdoc_options = ["--charset=UTF-8"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.3.5}
46
+ s.summary = %q{A plugin for the Merb framework that provides support for MongoID Models.}
47
+ s.test_files = [
48
+ "test/helper.rb",
49
+ "test/test_merb_mongoid.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ s.add_runtime_dependency(%q<merb-core>, [">= 1.0.9"])
58
+ s.add_runtime_dependency(%q<mongoid>, [">= 1.0.5"])
59
+ else
60
+ s.add_dependency(%q<merb-core>, [">= 1.0.9"])
61
+ s.add_dependency(%q<mongoid>, [">= 1.0.5"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<merb-core>, [">= 1.0.9"])
65
+ s.add_dependency(%q<mongoid>, [">= 1.0.5"])
66
+ end
67
+ end
68
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'merb_mongoid'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMerbMongoid < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb_mongoid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Bracco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-14 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mongoid
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.5
34
+ version:
35
+ description: A plugin for the Merb framework that provides support for MongoID Models.
36
+ email: code@webs.ly
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - Generators
48
+ - LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - VERSION
52
+ - lib/generators/model.rb
53
+ - lib/generators/resource_controller.rb
54
+ - lib/generators/templates/model/app/models/%file_name%.rb
55
+ - lib/generators/templates/resource_controller/app/controllers/%file_name%.rb
56
+ - lib/generators/templates/resource_controller/app/views/%file_name%/edit.html.erb
57
+ - lib/generators/templates/resource_controller/app/views/%file_name%/index.html.erb
58
+ - lib/generators/templates/resource_controller/app/views/%file_name%/new.html.erb
59
+ - lib/generators/templates/resource_controller/app/views/%file_name%/show.html.erb
60
+ - lib/merb/orms/mongoid/connection.rb
61
+ - lib/merb/orms/mongoid/database.yml.sample
62
+ - lib/merb_mongoid.rb
63
+ - merb_mongoid.gemspec
64
+ - test/helper.rb
65
+ - test/test_merb_mongoid.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/webs/merb_mongoid
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.5
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: A plugin for the Merb framework that provides support for MongoID Models.
94
+ test_files:
95
+ - test/helper.rb
96
+ - test/test_merb_mongoid.rb