adhearsion-mongoid 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +79 -0
- data/Rakefile +13 -0
- data/lib/adhearsion-mongoid.rb +1 -0
- data/lib/adhearsion/mongoid.rb +12 -0
- data/lib/adhearsion/mongoid/plugin.rb +26 -0
- data/lib/adhearsion/mongoid/plugin/service.rb +65 -0
- data/lib/adhearsion/mongoid/version.rb +5 -0
- data/spec/adhearsion/mongoid/plugin/service_spec.rb +53 -0
- data/spec/adhearsion/mongoid/plugin_spec.rb +23 -0
- data/spec/adhearsion/mongoid_spec.rb +11 -0
- data/spec/spec_helper.rb +11 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c3db3ebf88de59a56fdcf83eb4c6b828a31ed5e1
|
4
|
+
data.tar.gz: eb6c0230daf0ac660fc1e93b12924a7751efad09
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1212fb8a888e50f87207bb5f32f8f1d9ce6ed8e141d1cc53f77956184e98920709fe87619fb6da22e31b92748db83c6edcc96f46249f06e4ec71ebebf6630824
|
7
|
+
data.tar.gz: 2e29c974e4a4f57bfcffdf08a50777e30ce77b228928f84b0b164df22891d124e24d5d03f767c6d8a2ea3c60c9104d5f11f871353919c27531348abd1e10a657
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
adhearsion-mongoid
|
2
|
+
==================
|
3
|
+
|
4
|
+
adhearsion-mongoid is an [Adhearsion](https://github.com/adhearsion/adhearsion) Plugin providing [Mongoid](https://github.com/mongoid/mongoid) compatibility.
|
5
|
+
|
6
|
+
Features
|
7
|
+
--------
|
8
|
+
|
9
|
+
* Append compatibility with Mongoid 3.0+
|
10
|
+
|
11
|
+
Requirements
|
12
|
+
------------
|
13
|
+
|
14
|
+
* Adhearsion 2.0+
|
15
|
+
|
16
|
+
Testing environment
|
17
|
+
-------------------
|
18
|
+
|
19
|
+
Plugin has been tested with Adhearsion 2.4, Ruby 2.0 and Mongoid 4.0 (development).
|
20
|
+
|
21
|
+
Install
|
22
|
+
-------
|
23
|
+
|
24
|
+
Add `adhearsion-mongoid` to your Adhearsion app's Gemfile.
|
25
|
+
|
26
|
+
Plugin configuration (optional)
|
27
|
+
-------------------------------
|
28
|
+
|
29
|
+
In your Adhearsion app configuration file, add the following values:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Adhearsion.config[:adhearsion_mongoid] do |config|
|
33
|
+
config.models_paths = "lib/models"
|
34
|
+
config.config_path = "config/mongoid.yml"
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
Mongoid configuration
|
39
|
+
---------------------
|
40
|
+
|
41
|
+
By default, simply use "config/mongoid.yml" configuration file.
|
42
|
+
|
43
|
+
Usage
|
44
|
+
-----
|
45
|
+
|
46
|
+
Simply place your models in in your model directory ("lib/models" by default) and thats all.
|
47
|
+
|
48
|
+
|
49
|
+
Author
|
50
|
+
------
|
51
|
+
|
52
|
+
Original author: [Florent Morin](https://github.com/florentmorin)
|
53
|
+
(adapted from [Juan de Bravo](https://github.com/juandebravo) work)
|
54
|
+
Special Thanks
|
55
|
+
--------------
|
56
|
+
|
57
|
+
Thanks to [Juan de Bravo](https://github.com/juandebravo) for the [adhearsion-activerecord](https://github.com/adhearsion/adhearsion-activerecord) plugin
|
58
|
+
My plugin was simply adapted from it.
|
59
|
+
|
60
|
+
Links
|
61
|
+
-----
|
62
|
+
* [Source](https://github.com/morin-innovation/adhearsion-mongoid)
|
63
|
+
* [Documentation](http://rdoc.info/github/morin-innovation/adhearsion-mongoid/master/frames)
|
64
|
+
* [Bug Tracker](https://github.com/morin-innovation/adhearsion-mongoid/issues)
|
65
|
+
|
66
|
+
Note on Patches/Pull Requests
|
67
|
+
-----------------------------
|
68
|
+
|
69
|
+
* Fork the project.
|
70
|
+
* Make your feature addition or bug fix.
|
71
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
72
|
+
* Commit, do not mess with rakefile, version, or history.
|
73
|
+
* If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull
|
74
|
+
* Send me a pull request. Bonus points for topic branches.
|
75
|
+
|
76
|
+
Copyright
|
77
|
+
---------
|
78
|
+
|
79
|
+
Check [License file](https://github.com/morin-innovation/adhearsion-mongoid/blob/master/LICENSE)
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "bundler/setup"
|
3
|
+
|
4
|
+
|
5
|
+
require 'rspec/core'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
9
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
10
|
+
spec.rspec_opts = '--colour --format doc'
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :spec
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'adhearsion/mongoid'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Adhearsion
|
2
|
+
module Mongoid
|
3
|
+
|
4
|
+
##
|
5
|
+
# Adhearsion Plugin that defines the Mongoid configuration options
|
6
|
+
# and includes a hook to start the Mongoid service in Adhearsion initialization process
|
7
|
+
class Plugin < Adhearsion::Plugin
|
8
|
+
extend ActiveSupport::Autoload
|
9
|
+
|
10
|
+
autoload :Service, 'adhearsion/mongoid/plugin/service'
|
11
|
+
|
12
|
+
# Configure models path ('lib/models' by default) and Mongoid configuration path ('config/mongoid.yml' by default)
|
13
|
+
config :adhearsion_mongoid do
|
14
|
+
models_paths ['lib/models'], :desc => 'paths to directories containing models files to load'
|
15
|
+
config_path 'config/mongoid.yml', :desc => 'path to Mongoid configuration file'
|
16
|
+
end
|
17
|
+
|
18
|
+
# Include the Mongoid service in plugins initialization process
|
19
|
+
init :adhearsion_mongoid do
|
20
|
+
Service.start
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Adhearsion
|
2
|
+
module Mongoid
|
3
|
+
class Plugin
|
4
|
+
class Service
|
5
|
+
class << self
|
6
|
+
|
7
|
+
##
|
8
|
+
# Load the mongoid preferences, models and initiate logger
|
9
|
+
def start
|
10
|
+
logger.info "Loading Mongoid preferences"
|
11
|
+
|
12
|
+
params = config.to_hash.select { |k,v| !v.nil? }
|
13
|
+
|
14
|
+
::Mongoid.load!(*params.delete(:config_path), ENV['AHN_ENV'])
|
15
|
+
|
16
|
+
logger.info "Loading Mongoid models"
|
17
|
+
require_models(*params.delete(:models_paths))
|
18
|
+
|
19
|
+
logger.info "Loading Mongoid logger"
|
20
|
+
::Mongoid.logger = logger
|
21
|
+
::Moped.logger = logger
|
22
|
+
|
23
|
+
logger.info "Mongoid successfully configured"
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# stop service (unused)
|
28
|
+
def stop
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
##
|
34
|
+
# models are '.rb' file in models directory
|
35
|
+
def require_models(*paths)
|
36
|
+
paths.each do |path|
|
37
|
+
Dir.foreach(path) do |filename|
|
38
|
+
pn = Pathname.new path
|
39
|
+
|
40
|
+
if pn.relative?
|
41
|
+
root_path = Adhearsion.config.root
|
42
|
+
root_path ||= Dir.pwd
|
43
|
+
full_path = File.join root_path, path, filename
|
44
|
+
else
|
45
|
+
full_path = File.join path, filename
|
46
|
+
end
|
47
|
+
|
48
|
+
if File.file? full_path and File.extname(full_path) == ".rb"
|
49
|
+
require full_path
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Access to mongoid plugin configuration
|
57
|
+
def config
|
58
|
+
@config ||= Plugin.config
|
59
|
+
end
|
60
|
+
|
61
|
+
end # class << self
|
62
|
+
end # Service
|
63
|
+
end # Plugin
|
64
|
+
end # Mongoid
|
65
|
+
end # Adhearsion
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
ENV['AHN_ENV'] = 'test'
|
4
|
+
|
5
|
+
describe Adhearsion::Mongoid::Plugin::Service do
|
6
|
+
|
7
|
+
describe "when starting the Mongoid connection" do
|
8
|
+
|
9
|
+
def tmp_models_dir_path
|
10
|
+
path = File.join Dir.tmpdir, "models"
|
11
|
+
|
12
|
+
unless File.directory? path
|
13
|
+
FileUtils.mkdir path
|
14
|
+
end
|
15
|
+
|
16
|
+
path
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_tempmodel_with_contents(contents)
|
20
|
+
path = File.join tmp_models_dir_path, "user.rb"
|
21
|
+
file = File.new(path, "w+")
|
22
|
+
file.puts contents
|
23
|
+
file.flush
|
24
|
+
path
|
25
|
+
end
|
26
|
+
|
27
|
+
def sample_user_model
|
28
|
+
<<-CODE
|
29
|
+
class User
|
30
|
+
include Mongoid::Document
|
31
|
+
|
32
|
+
field :name, type: String
|
33
|
+
end
|
34
|
+
CODE
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should make any required models available" do
|
38
|
+
path = create_tempmodel_with_contents sample_user_model
|
39
|
+
|
40
|
+
Adhearsion.config.adhearsion_mongoid.models_paths = [tmp_models_dir_path]
|
41
|
+
Adhearsion::Mongoid::Plugin::Service.start
|
42
|
+
|
43
|
+
u = User.new
|
44
|
+
u.should respond_to :name
|
45
|
+
|
46
|
+
File.delete path
|
47
|
+
|
48
|
+
Dir.delete tmp_models_dir_path
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Adhearsion::Mongoid::Plugin do
|
4
|
+
|
5
|
+
describe "while accessing the plugin configuration" do
|
6
|
+
|
7
|
+
it "should retrieve a valid configuration instance" do
|
8
|
+
Adhearsion.config.adhearsion_mongoid.should be_instance_of Loquacious::Configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should configure properly the models_paths" do
|
12
|
+
Adhearsion.config[:adhearsion_mongoid].models_paths.class.should == Array
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "while loading plugins" do
|
18
|
+
it "should load the init block and start the service" do
|
19
|
+
Adhearsion::Mongoid::Plugin::Service.should_receive(:start).once.and_return true
|
20
|
+
Adhearsion::Plugin.init_plugins
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adhearsion-mongoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Florent Morin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: adhearsion
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.10
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.10
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mongoid
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: This gem provides an Adhearsion plugin to handle the Mongoid and database
|
98
|
+
integration
|
99
|
+
email:
|
100
|
+
- florent.morin@morin-innovation.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- lib/adhearsion/mongoid/plugin/service.rb
|
106
|
+
- lib/adhearsion/mongoid/plugin.rb
|
107
|
+
- lib/adhearsion/mongoid/version.rb
|
108
|
+
- lib/adhearsion/mongoid.rb
|
109
|
+
- lib/adhearsion-mongoid.rb
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- Gemfile
|
113
|
+
- spec/adhearsion/mongoid/plugin/service_spec.rb
|
114
|
+
- spec/adhearsion/mongoid/plugin_spec.rb
|
115
|
+
- spec/adhearsion/mongoid_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
homepage: https://github.com/morin-innovation
|
118
|
+
licenses: []
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project: adhearsion-mongoid
|
136
|
+
rubygems_version: 2.0.7
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: This gem provides an Adhearsion plugin to handle the Mongoid and database
|
140
|
+
integration
|
141
|
+
test_files:
|
142
|
+
- spec/adhearsion/mongoid/plugin/service_spec.rb
|
143
|
+
- spec/adhearsion/mongoid/plugin_spec.rb
|
144
|
+
- spec/adhearsion/mongoid_spec.rb
|
145
|
+
- spec/spec_helper.rb
|