mongoid-plugins 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mongoid-plugins (0.0.1)
5
+ mongoid (>= 2.0.0.beta.20)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.0.3)
11
+ activesupport (= 3.0.3)
12
+ builder (~> 2.1.2)
13
+ i18n (~> 0.4)
14
+ activesupport (3.0.3)
15
+ autotest (4.4.5)
16
+ bson (1.1.2)
17
+ builder (2.1.2)
18
+ diff-lcs (1.1.2)
19
+ haml (2.2.24)
20
+ hanna (0.1.12)
21
+ haml (~> 2.2.8)
22
+ rake (~> 0.8.2)
23
+ rdoc (~> 2.3.0)
24
+ i18n (0.4.2)
25
+ mongo (1.1.2)
26
+ bson (>= 1.1.1)
27
+ mongoid (2.0.0.beta.20)
28
+ activemodel (~> 3.0)
29
+ mongo (~> 1.1)
30
+ tzinfo (~> 0.3.22)
31
+ will_paginate (~> 3.0.pre)
32
+ rake (0.8.7)
33
+ rdoc (2.3.0)
34
+ rspec (2.1.0)
35
+ rspec-core (~> 2.1.0)
36
+ rspec-expectations (~> 2.1.0)
37
+ rspec-mocks (~> 2.1.0)
38
+ rspec-core (2.1.0)
39
+ rspec-expectations (2.1.0)
40
+ diff-lcs (~> 1.1.2)
41
+ rspec-mocks (2.1.0)
42
+ tzinfo (0.3.23)
43
+ will_paginate (3.0.pre2)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ autotest (>= 4.3.2)
50
+ hanna (>= 0.1.12)
51
+ mongoid (>= 2.0.0.beta.20)
52
+ mongoid-plugins!
53
+ rspec (~> 2.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Benedikt Deicke
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,70 @@
1
+ = mongoid-plugins
2
+
3
+ Easily add and configure plugins for Mongoid
4
+
5
+ == Requirements
6
+
7
+ * mongoid (>= 2.0.0.beta.20)
8
+
9
+ == Install
10
+
11
+ To install mongoid-plugins, simply add it to your Gemfile:
12
+
13
+ gem 'mongoid-plugins', :require => 'mongoid/plugins'
14
+
15
+ In order to get the latest development version of mongoid-plugins:
16
+
17
+ gem 'mongoid-plugins', :git => 'git://github.com/benedikt/mongoid-plugins', :require => 'mongoid/plugins'
18
+
19
+ You might want to remove the <tt>:require => 'mongoid/plugins'</tt> option and explicitly <tt>require 'mongoid/plugins'</tt> where needed and finally run
20
+
21
+ bundle install
22
+
23
+
24
+ == Usage
25
+
26
+ class SomeDocument
27
+ include Mongoid::Document
28
+
29
+ plugin SomePlugin do |c|
30
+ c.some_setting = false
31
+ end
32
+ end
33
+
34
+
35
+ == Writing Plugins
36
+
37
+ It's fairly easy to write plugins compatible with Mongoid::Plugins. In fact they're simply Ruby modules. It's possible to add default options by defining a <tt>default_plugin_options</tt> method on your module returning a hash:
38
+
39
+ module SomePlugin
40
+ def self.default_plugin_options
41
+ {
42
+ :some_default_setting => 100
43
+ }
44
+ end
45
+ end
46
+
47
+ To access the options from within your plugin just call <tt>plugin_options_for(SomePlugin)</tt>:
48
+
49
+ module SomePlugin
50
+ def a_plugin_method
51
+ if self.plugin_options_for(SomePlugin).do_something
52
+ # Do something :-)
53
+ end
54
+ end
55
+ end
56
+
57
+
58
+ == Known issues
59
+
60
+ See http://github.com/benedikt/mongoid-plugins/issues
61
+
62
+
63
+ == Repository
64
+
65
+ See http://github.com/benedikt/mongoid-plugins and feel free to fork it!
66
+
67
+
68
+ == Copyright
69
+
70
+ Copyright (c) 2010 Benedikt Deicke. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'hanna/rdoctask'
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ spec = Gem::Specification.load('mongoid-plugins.gemspec')
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task :default => :spec
11
+
12
+ Rake::RDocTask.new do |rdoc|
13
+ rdoc.rdoc_dir = 'doc'
14
+ rdoc.title = '#{spec.name} #{spec.version}'
15
+ rdoc.options += spec.rdoc_options
16
+ rdoc.rdoc_files.include(spec.extra_rdoc_files)
17
+ rdoc.rdoc_files.include('lib/**/*.rb')
18
+ end
@@ -0,0 +1,32 @@
1
+ module Mongoid
2
+ module Plugins
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ cattr_accessor :_plugin_options
7
+ self._plugin_options = {}
8
+ end
9
+
10
+ module ClassMethods
11
+ def plugin(mod, &block)
12
+ _plugin_options[mod] = ActiveSupport::OrderedOptions.new.tap do |options|
13
+ options.merge!(mod.default_plugin_options) if mod.respond_to? :default_plugin_options
14
+ yield(options) if block_given?
15
+ end
16
+
17
+ include(mod)
18
+ end
19
+
20
+ def plugin_options_for(mod)
21
+ raise "#{mod} is not loaded as a plugin" unless _plugin_options.include?(mod)
22
+ _plugin_options[mod]
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ module Mongoid
29
+ module Document
30
+ include Mongoid::Plugins
31
+ end
32
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::Plugins do
4
+
5
+ let(:klass) { Class.new }
6
+ let(:plugin) { Module.new }
7
+
8
+ before(:each) do
9
+ klass.send(:include, Mongoid::Document)
10
+ end
11
+
12
+ it 'should be auto included into Mongoid::Document' do
13
+ klass.should include Mongoid::Plugins
14
+ end
15
+
16
+ it 'should add a .plugin method' do
17
+ klass.should respond_to :plugin
18
+ end
19
+
20
+ it 'should add a .plugin_options_for method' do
21
+ klass.should respond_to :plugin_options_for
22
+ end
23
+
24
+ describe '.plugin' do
25
+ it 'should include the given module' do
26
+ klass.plugin(plugin)
27
+ klass.should include plugin
28
+ end
29
+
30
+ it 'should store plugin options for the given module' do
31
+ klass.plugin(plugin)
32
+ klass.plugin_options_for(plugin).should be_kind_of ActiveSupport::OrderedOptions
33
+ end
34
+
35
+ it 'should call .default_plugin_options on the given module' do
36
+ plugin.should_receive(:respond_to?).with(:default_plugin_options).and_return(true)
37
+ plugin.should_receive(:default_plugin_options).and_return({})
38
+ klass.plugin(plugin)
39
+ end
40
+
41
+ it 'should not call .default_plugin_options on the given module if it is not defined' do
42
+ plugin.should_receive(:respond_to?).with(:default_plugin_options).and_return(false)
43
+ plugin.should_not_receive(:default_plugin_options).and_return({})
44
+ klass.plugin(plugin)
45
+ end
46
+
47
+ it 'should use the hash returned by default_plugin_options to populate the plugin options hash' do
48
+ plugin.should_receive(:respond_to?).with(:default_plugin_options).and_return(true)
49
+ plugin.should_receive(:default_plugin_options).and_return({ :default => true })
50
+ klass.plugin(plugin)
51
+ klass.plugin_options_for(plugin).should eql({ :default => true })
52
+ end
53
+
54
+ it 'should pass the options hash into the block' do
55
+ klass.plugin(plugin) do |c|
56
+ c.should be_kind_of ActiveSupport::OrderedOptions
57
+ end
58
+ end
59
+ end
60
+
61
+ describe '.plugin_options_for' do
62
+ before(:each) do
63
+ plugin.stub!(:default_plugin_options).and_return({
64
+ :active => true,
65
+ :other => 'Option',
66
+ :setting => 10
67
+ })
68
+
69
+ klass.plugin(plugin) do |c|
70
+ c.active = false
71
+ c.other = 'Awesome'
72
+ end
73
+ end
74
+
75
+ it 'should return the options for the given module' do
76
+ klass.plugin_options_for(plugin).should be_kind_of ActiveSupport::OrderedOptions
77
+ end
78
+
79
+ it 'should include the given options' do
80
+ options = klass.plugin_options_for(plugin)
81
+ options.active.should be_false
82
+ options.other.should eql('Awesome')
83
+ options.setting.should eql(10)
84
+ end
85
+
86
+ it 'should raise an exception when given plugin is not available' do
87
+ expect { klass.plugin_options_for(Module.new) }.to raise_error /is not loaded/
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'mongoid'
5
+ require 'mongoid/plugins'
6
+
7
+ require 'rspec'
8
+
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
10
+
11
+ RSpec.configure do |config|
12
+ config.mock_with :rspec
13
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-plugins
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Benedikt Deicke
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-20 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: mongoid
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 62196427
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 0
34
+ - beta
35
+ - 20
36
+ version: 2.0.0.beta.20
37
+ type: :runtime
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: rspec
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 2
50
+ - 0
51
+ version: "2.0"
52
+ type: :development
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: autotest
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 55
63
+ segments:
64
+ - 4
65
+ - 3
66
+ - 2
67
+ version: 4.3.2
68
+ type: :development
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: hanna
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ - 1
82
+ - 12
83
+ version: 0.1.12
84
+ type: :development
85
+ version_requirements: *id004
86
+ description: Easily add and configure plugins for Mongoid
87
+ email: benedikt@synatic.net
88
+ executables: []
89
+
90
+ extensions: []
91
+
92
+ extra_rdoc_files:
93
+ - README.rdoc
94
+ - LICENSE
95
+ files:
96
+ - lib/mongoid/plugins.rb
97
+ - spec/mongoid/plugins_spec.rb
98
+ - spec/spec_helper.rb
99
+ - LICENSE
100
+ - README.rdoc
101
+ - Rakefile
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - .rspec
105
+ has_rdoc: true
106
+ homepage: http://github.com/benedikt/mongoid-plugins
107
+ licenses: []
108
+
109
+ post_install_message:
110
+ rdoc_options:
111
+ - --main
112
+ - README.rdoc
113
+ - --charset=UTF-8
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.3.7
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Easily add and configure plugins for Mongoid
141
+ test_files: []
142
+