merb_mongomapper 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ pkg/
2
+ .DS_Store
3
+ *.gem
4
+ *~
@@ -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
@@ -0,0 +1,8 @@
1
+ == 0.1.6 ==
2
+
3
+ * Update mongomapper gem
4
+ * Fix error in database.yml sample
5
+
6
+ == 0.1.5 ==
7
+
8
+ * Update compatibility to mongoDB ruby driver 0.14444
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 AF83
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,22 @@
1
+ merb_mongomapper
2
+ ==============
3
+
4
+ A plugin for the Merb framework that provides support for MongoMapper Models.
5
+
6
+ Currently based around MongoMapper::Document.
7
+
8
+
9
+
10
+ = Connection options
11
+
12
+ Merb MongoMapper plugin uses config/database.yml for connection configuration.
13
+
14
+ Options are:
15
+
16
+ * host. provide a string or an array of strings to attempt connections with
17
+ * database.
18
+
19
+
20
+ Uses the MongDB client MongMapper by John Nunemaker .
21
+
22
+ Hacked together by studying the merb_couchrest plugin.
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ require 'merb-core'
5
+ require 'merb-core/tasks/merb'
6
+
7
+ GEM_NAME = "merb_mongomapper"
8
+ AUTHOR = "Cyril Mougel"
9
+ EMAIL = "cyril.mougel@gmail.com"
10
+ HOMEPAGE = "http://github.com/shingara/merb_mongomapper"
11
+ SUMMARY = "Merb ORM plugin that provides support for MongoMapper Models"
12
+
13
+ begin
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = GEM_NAME
17
+ gem.summary = SUMMARY
18
+ gem.email = EMAIL
19
+ gem.homepage = HOMEPAGE
20
+ gem.authors = ["Cyril Mougel"]
21
+ gem.rubyforge_project = "merb_mongomapper"
22
+
23
+ gem.add_dependency('merb-core', '>= 1.0.9')
24
+ gem.add_dependency("mongo_mapper", "~>0.5.5")
25
+ end
26
+
27
+ Jeweler::RubyforgeTasks.new
28
+ rescue LoadError
29
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
30
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.7
@@ -0,0 +1,4 @@
1
+ Merb::Generators::ModelGenerator.template :model_mongomapper, :orm => :mongomapper 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_mongomapper, :orm => :mongomapper 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}_mongomapper".to_sym,
8
+ :orm => :mongomapper, :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,5 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %>
3
+ include MongoMapper::Document
4
+ end
5
+ <% 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,68 @@
1
+ require "fileutils"
2
+ require "mongo_mapper"
3
+
4
+
5
+ module Merb
6
+ module Orms
7
+ module MongoMapper
8
+
9
+ class << self
10
+
11
+ def config_file() Merb.dir_for(:config) / "database.yml" end
12
+ def sample_dest() Merb.dir_for(:config) / "database.yml.sample" end
13
+ def sample_source() File.dirname(__FILE__) / "database.yml.sample" end
14
+
15
+ def copy_sample_config
16
+ FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
17
+ end
18
+
19
+ def get_config
20
+ # Convert string keys to symbols
21
+ full_config = Erubis.load_yaml_file(config_file)
22
+ config = (Merb::Plugins.config[:merb_mongomapper] = {})
23
+ (full_config[Merb.environment.to_sym] || full_config[Merb.environment] || full_config[:development]).each do |key, value|
24
+ config[key.to_sym] = value
25
+ end
26
+ config
27
+ end
28
+
29
+ def config
30
+ @config ||= get_config
31
+ end
32
+
33
+ def database
34
+ (config[:database_prefix] || '') + (config[:database] || '') + (config[:database_suffix] || '')
35
+ end
36
+
37
+ def connect
38
+ no_database_file unless File.exists?(config_file)
39
+
40
+ # it is possible that we have been passed an array of hosts - attempt each in turn until one is found
41
+ host = config[:host] || 'localhost'
42
+ port = config[:port] || 27017
43
+ begin
44
+ Merb.logger.info!("Attempting connection to the '#{database}' database on '#{host}' ...")
45
+ ::MongoMapper.connection = Mongo::Connection.new(host, port)
46
+ Merb.logger.info!("Connected to '#{host}'")
47
+ ::MongoMapper.database = database
48
+ return true
49
+ rescue Errno::ECONNREFUSED
50
+ Merb.logger.info!("#{host} not available")
51
+ rescue => e
52
+ Merb.logger.info!("Connection Error: #{e}")
53
+ Merb.print_colorized_backtrace(e)
54
+ exit(1)
55
+ end
56
+ end
57
+
58
+ def no_database_file
59
+ copy_sample_config
60
+ Merb.logger.set_log(STDERR)
61
+ Merb.logger.error! "No database.yml file found at #{config_file}."
62
+ Merb.logger.error! "A sample file was created called #{sample_dest} for you to copy and edit."
63
+ exit(1)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,14 @@
1
+ ---
2
+ # This is a sample database file for the CouchRest ORM
3
+ :development: &defaults
4
+ :database_prefix:
5
+ :database_suffix: _<%= Merb.env %>
6
+ :database: sample
7
+ :host: localhost
8
+ :port: 27017
9
+
10
+ :test:
11
+ <<: *defaults
12
+
13
+ :production:
14
+ <<: *defaults
@@ -0,0 +1,22 @@
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_mongomapper] = {}
6
+ require File.join(File.dirname(__FILE__) / "merb" / "orms" / "mongomapper" / "connection" )
7
+
8
+
9
+ class Merb::Orms::MongoMapper::Connect < Merb::BootLoader
10
+ after BeforeAppLoads
11
+
12
+ def self.run
13
+ Merb::Orms::MongoMapper.connect
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+
20
+ class MerbMongomapper
21
+ VERSION = '0.1.7'
22
+ end
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{merb_mongomapper}
8
+ s.version = "0.1.7"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Cyril Mougel"]
12
+ s.date = %q{2009-10-18}
13
+ s.email = %q{cyril.mougel@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "Generators",
21
+ "History.txt",
22
+ "LICENSE",
23
+ "README",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/generators/model.rb",
27
+ "lib/generators/resource_controller.rb",
28
+ "lib/generators/templates/model/app/models/%file_name%.rb",
29
+ "lib/generators/templates/resource_controller/app/controllers/%file_name%.rb",
30
+ "lib/generators/templates/resource_controller/app/views/%file_name%/edit.html.erb",
31
+ "lib/generators/templates/resource_controller/app/views/%file_name%/index.html.erb",
32
+ "lib/generators/templates/resource_controller/app/views/%file_name%/new.html.erb",
33
+ "lib/generators/templates/resource_controller/app/views/%file_name%/show.html.erb",
34
+ "lib/merb/orms/mongomapper/connection.rb",
35
+ "lib/merb/orms/mongomapper/database.yml.sample",
36
+ "lib/merb_mongomapper.rb",
37
+ "merb_mongomapper.gemspec",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+ s.has_rdoc = true
41
+ s.homepage = %q{http://github.com/shingara/merb_mongomapper}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubyforge_project = %q{merb_mongomapper}
45
+ s.rubygems_version = %q{1.3.2}
46
+ s.summary = %q{Merb ORM plugin that provides support for MongoMapper Models}
47
+ s.test_files = [
48
+ "spec/spec_helper.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_runtime_dependency(%q<merb-core>, [">= 1.0.9"])
57
+ s.add_runtime_dependency(%q<mongo_mapper>, ["~> 0.5.5"])
58
+ else
59
+ s.add_dependency(%q<merb-core>, [">= 1.0.9"])
60
+ s.add_dependency(%q<mongo_mapper>, ["~> 0.5.5"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<merb-core>, [">= 1.0.9"])
64
+ s.add_dependency(%q<mongo_mapper>, ["~> 0.5.5"])
65
+ end
66
+ end
@@ -0,0 +1 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb_mongomapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.7
5
+ platform: ruby
6
+ authors:
7
+ - Cyril Mougel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-18 00:00:00 +02: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: mongo_mapper
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.5
34
+ version:
35
+ description:
36
+ email: cyril.mougel@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README
44
+ files:
45
+ - .gitignore
46
+ - Generators
47
+ - History.txt
48
+ - LICENSE
49
+ - README
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/mongomapper/connection.rb
61
+ - lib/merb/orms/mongomapper/database.yml.sample
62
+ - lib/merb_mongomapper.rb
63
+ - merb_mongomapper.gemspec
64
+ - spec/spec_helper.rb
65
+ has_rdoc: true
66
+ homepage: http://github.com/shingara/merb_mongomapper
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project: merb_mongomapper
89
+ rubygems_version: 1.3.2
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Merb ORM plugin that provides support for MongoMapper Models
93
+ test_files:
94
+ - spec/spec_helper.rb