shingara-merb_mongomapper 0.1.2

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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/
2
+ .DS_Store
3
+ *.gem
4
+ *~
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) 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.
data/Rakefile ADDED
@@ -0,0 +1,41 @@
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
+ GEM_VERSION = "0.1.1"
9
+ AUTHOR = "Cyril Mougel"
10
+ EMAIL = "cyril.mougelo@gmail.com"
11
+ HOMEPAGE = "http://github.com/shingara/merb_mongomapper"
12
+ SUMMARY = "Merb ORM plugin that provides support for MongoMapper Models"
13
+
14
+ begin
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ gem.name = GEM_NAME
18
+ gem.summary = SUMMARY
19
+ gem.email = EMAIL
20
+ gem.homepage = HOMEPAGE
21
+ gem.authors = ["Cyril Mougel"]
22
+ gem.rubyforge_project = "merb_mongomapper"
23
+
24
+ gem.add_dependency('merb-core', '>= 1.0.9')
25
+ gem.add_dependency("mongomapper", "~> 0.3.2")
26
+ end
27
+
28
+ Jeweler::RubyforgeTasks.new
29
+ rescue LoadError
30
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
31
+ end
32
+
33
+ desc "install the plugin as a gem"
34
+ task :install do
35
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
36
+ end
37
+
38
+ desc "Uninstall the gem"
39
+ task :uninstall do
40
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -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 "mongomapper"
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] + [: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 = XGen::Mongo::Driver::Mongo.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,16 @@
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
+ :database: sample
13
+
14
+ :production:
15
+ <<: *defaults
16
+ :database: sample
@@ -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_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
@@ -0,0 +1,62 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{merb_mongomapper}
5
+ s.version = "0.1.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Cyril Mougel"]
9
+ s.date = %q{2009-08-17}
10
+ s.email = %q{cyril.mougelo@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README"
14
+ ]
15
+ s.files = [
16
+ ".gitignore",
17
+ "Generators",
18
+ "LICENSE",
19
+ "README",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/generators/model.rb",
23
+ "lib/generators/resource_controller.rb",
24
+ "lib/generators/templates/model/app/models/%file_name%.rb",
25
+ "lib/generators/templates/resource_controller/app/controllers/%file_name%.rb",
26
+ "lib/generators/templates/resource_controller/app/views/%file_name%/edit.html.erb",
27
+ "lib/generators/templates/resource_controller/app/views/%file_name%/index.html.erb",
28
+ "lib/generators/templates/resource_controller/app/views/%file_name%/new.html.erb",
29
+ "lib/generators/templates/resource_controller/app/views/%file_name%/show.html.erb",
30
+ "lib/merb/orms/mongomapper/connection.rb",
31
+ "lib/merb/orms/mongomapper/database.yml.sample",
32
+ "lib/merb_mongomapper.rb",
33
+ "merb_mongomapper.gemspec",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.has_rdoc = true
37
+ s.homepage = %q{http://github.com/shingara/merb_mongomapper}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubyforge_project = %q{merb_mongomapper}
41
+ s.rubygems_version = %q{1.3.2}
42
+ s.summary = %q{Merb ORM plugin that provides support for MongoMapper Models}
43
+ s.test_files = [
44
+ "spec/spec_helper.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<merb-core>, [">= 1.0.9"])
53
+ s.add_runtime_dependency(%q<mongomapper>, ["~> 0.3.2"])
54
+ else
55
+ s.add_dependency(%q<merb-core>, [">= 1.0.9"])
56
+ s.add_dependency(%q<mongomapper>, ["~> 0.3.2"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<merb-core>, [">= 1.0.9"])
60
+ s.add_dependency(%q<mongomapper>, ["~> 0.3.2"])
61
+ end
62
+ end
@@ -0,0 +1 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shingara-merb_mongomapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Cyril Mougel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-17 00:00:00 -07: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: mongomapper
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.2
34
+ version:
35
+ description:
36
+ email: cyril.mougelo@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README
44
+ files:
45
+ - .gitignore
46
+ - Generators
47
+ - LICENSE
48
+ - README
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/generators/model.rb
52
+ - lib/generators/resource_controller.rb
53
+ - lib/generators/templates/model/app/models/%file_name%.rb
54
+ - lib/generators/templates/resource_controller/app/controllers/%file_name%.rb
55
+ - lib/generators/templates/resource_controller/app/views/%file_name%/edit.html.erb
56
+ - lib/generators/templates/resource_controller/app/views/%file_name%/index.html.erb
57
+ - lib/generators/templates/resource_controller/app/views/%file_name%/new.html.erb
58
+ - lib/generators/templates/resource_controller/app/views/%file_name%/show.html.erb
59
+ - lib/merb/orms/mongomapper/connection.rb
60
+ - lib/merb/orms/mongomapper/database.yml.sample
61
+ - lib/merb_mongomapper.rb
62
+ - merb_mongomapper.gemspec
63
+ - spec/spec_helper.rb
64
+ has_rdoc: true
65
+ homepage: http://github.com/shingara/merb_mongomapper
66
+ licenses:
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ requirements: []
85
+
86
+ rubyforge_project: merb_mongomapper
87
+ rubygems_version: 1.3.5
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Merb ORM plugin that provides support for MongoMapper Models
91
+ test_files:
92
+ - spec/spec_helper.rb