mordor 0.2.6 → 0.2.7
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/lib/mordor.rb +4 -10
- data/lib/mordor/config.rb +82 -0
- data/mordor.gemspec +2 -2
- data/spec/mordor/connection_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -9
- metadata +4 -3
data/lib/mordor.rb
CHANGED
@@ -3,6 +3,7 @@ require 'mongo'
|
|
3
3
|
require 'extlib'
|
4
4
|
require 'json'
|
5
5
|
require 'mordor/version'
|
6
|
+
require 'mordor/config'
|
6
7
|
require 'mordor/collection'
|
7
8
|
require 'mordor/resource'
|
8
9
|
|
@@ -82,17 +83,10 @@ class Time
|
|
82
83
|
end
|
83
84
|
|
84
85
|
module Mordor
|
85
|
-
CONFIG = {
|
86
|
-
:hostname => 'localhost',
|
87
|
-
:port => 27017,
|
88
|
-
:database => 'development'
|
89
|
-
}
|
90
|
-
|
91
86
|
def connection
|
92
|
-
@connection ||= Mongo::Connection.new(
|
93
|
-
@connection.autenticate(
|
94
|
-
@connection.db(
|
87
|
+
@connection ||= Mongo::Connection.new(Mordor::Config[:hostname], Mordor::Config[:port])
|
88
|
+
@connection.autenticate(Mordor::Config[:username], Mordor::Config[:password]) if Mordor::Config[:username]
|
89
|
+
@connection.db(Mordor::Config[:database])
|
95
90
|
end
|
96
91
|
module_function :connection
|
97
|
-
|
98
92
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Mordor
|
2
|
+
class Config
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# Yields the configuration.
|
6
|
+
#
|
7
|
+
# ==== Block parameters
|
8
|
+
# c<Hash>:: The configuration parameters.
|
9
|
+
#
|
10
|
+
# ==== Examples
|
11
|
+
# Merb::Config.use do |config|
|
12
|
+
# config[:exception_details] = false
|
13
|
+
# config[:log_stream] = STDOUT
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# ==== Returns
|
17
|
+
# nil
|
18
|
+
#
|
19
|
+
# :api: publicdef use
|
20
|
+
def use
|
21
|
+
@configuration ||= {}
|
22
|
+
yield @configuration
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
# Retrieve the value of a config entry.
|
27
|
+
#
|
28
|
+
# ==== Parameters
|
29
|
+
# key<Object>:: The key to retrieve the parameter for.
|
30
|
+
#
|
31
|
+
# ==== Returns
|
32
|
+
# Object:: The value of the configuration parameter.
|
33
|
+
#
|
34
|
+
# :api: public
|
35
|
+
def [](key)
|
36
|
+
(@configuration ||= setup)[key]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Set the value of a config entry.
|
40
|
+
#
|
41
|
+
# ==== Parameters
|
42
|
+
# key<Object>:: The key to set the parameter for.
|
43
|
+
# val<Object>:: The value of the parameter.
|
44
|
+
#
|
45
|
+
# :api: public
|
46
|
+
def []=(key, val)
|
47
|
+
(@configuration ||= setup)[key] = val
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# Returns the hash of default config values for Merb.
|
53
|
+
#
|
54
|
+
# ==== Returns
|
55
|
+
# Hash:: The defaults for the config.
|
56
|
+
#
|
57
|
+
# :api: private
|
58
|
+
def defaults
|
59
|
+
@defaults ||= {
|
60
|
+
:hostname => 'localhost',
|
61
|
+
:port => 27017,
|
62
|
+
:database => 'development'
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
# Sets up the configuration by storing the given settings.
|
67
|
+
#
|
68
|
+
# ==== Parameters
|
69
|
+
# settings<Hash>::
|
70
|
+
# Configuration settings to use. These are merged with the defaults.
|
71
|
+
#
|
72
|
+
# ==== Returns
|
73
|
+
# The configuration as a hash.
|
74
|
+
#
|
75
|
+
# :api: private
|
76
|
+
def setup(settings = {})
|
77
|
+
@configuration = defaults.merge(settings)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/mordor.gemspec
CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.name = "mordor"
|
3
3
|
|
4
4
|
# Do not set the version and date field manually, this is done by the release script
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.7"
|
6
6
|
s.date = "2012-01-04"
|
7
7
|
|
8
8
|
s.summary = "mordor"
|
@@ -29,6 +29,6 @@ Gem::Specification.new do |s|
|
|
29
29
|
|
30
30
|
# The files and test_files directives are set automatically by the release script.
|
31
31
|
# Do not change them by hand, but make sure to add the files to the git repository.
|
32
|
-
s.files = %w(.gitignore Gemfile Gemfile.lock README.md Rakefile lib/mordor.rb lib/mordor/collection.rb lib/mordor/resource.rb lib/mordor/version.rb mordor.gemspec spec/mordor/collection_spec.rb spec/mordor/connection_spec.rb spec/mordor/resource_spec.rb spec/spec.opts spec/spec_helper.rb tasks/github-gem.rake)
|
32
|
+
s.files = %w(.gitignore Gemfile Gemfile.lock README.md Rakefile lib/mordor.rb lib/mordor/collection.rb lib/mordor/config.rb lib/mordor/resource.rb lib/mordor/version.rb mordor.gemspec spec/mordor/collection_spec.rb spec/mordor/connection_spec.rb spec/mordor/resource_spec.rb spec/spec.opts spec/spec_helper.rb tasks/github-gem.rake)
|
33
33
|
end
|
34
34
|
|
data/spec/spec_helper.rb
CHANGED
@@ -4,17 +4,11 @@ require 'mongo'
|
|
4
4
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
5
|
require 'mordor'
|
6
6
|
|
7
|
-
|
8
|
-
CONFIG = {
|
9
|
-
:hostname => 'localhost',
|
10
|
-
:port => 27017,
|
11
|
-
:database => 'test'
|
12
|
-
}
|
13
|
-
end
|
7
|
+
Mordor::Config[:database] = 'test'
|
14
8
|
|
15
9
|
def clean_sheet
|
16
|
-
@connection ||= Mongo::Connection.new(Mordor::
|
17
|
-
@db ||= @connection[Mordor::
|
10
|
+
@connection ||= Mongo::Connection.new(Mordor::Config[:hostname], Mordor::Config[:port])
|
11
|
+
@db ||= @connection[Mordor::Config[:database]]
|
18
12
|
|
19
13
|
['TestResource', 'TestTimedResource'].each do |resource|
|
20
14
|
if Object.const_defined?(resource)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mordor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 7
|
10
|
+
version: 0.2.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jan-Willem Koelewijn
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- Rakefile
|
179
179
|
- lib/mordor.rb
|
180
180
|
- lib/mordor/collection.rb
|
181
|
+
- lib/mordor/config.rb
|
181
182
|
- lib/mordor/resource.rb
|
182
183
|
- lib/mordor/version.rb
|
183
184
|
- mordor.gemspec
|