bovem 0.5.0 → 0.6.0
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/Gemfile.lock +1 -1
- data/bovem.gemspec +1 -3
- data/lib/bovem.rb +1 -1
- data/lib/bovem/configuration.rb +22 -3
- data/lib/bovem/version.rb +1 -1
- data/spec/bovem/configuration_spec.rb +16 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/bovem.gemspec
CHANGED
data/lib/bovem.rb
CHANGED
data/lib/bovem/configuration.rb
CHANGED
@@ -7,11 +7,12 @@
|
|
7
7
|
module Bovem
|
8
8
|
# This class holds the configuration of the applicaton.
|
9
9
|
#
|
10
|
-
# Extend this class and add valid properties via
|
10
|
+
# Extend this class and add valid properties via {property property} method.
|
11
11
|
# Example:
|
12
|
+
#
|
12
13
|
# ```ruby
|
13
14
|
# class MyConfiguration << Bovem::Configuration
|
14
|
-
#
|
15
|
+
# property :property, :default => "VALUE"
|
15
16
|
# end
|
16
17
|
#
|
17
18
|
# # Configuration file
|
@@ -19,17 +20,19 @@ module Bovem
|
|
19
20
|
# ```
|
20
21
|
class Configuration
|
21
22
|
# Creates a new configuration.
|
23
|
+
#
|
22
24
|
# A configuration file is a plain Ruby file with a top-level {Configuration config} object.
|
23
25
|
#
|
24
26
|
# @param file [String] The file to read.
|
25
27
|
# @param overrides [Hash] A set of values which override those set in the configuration file.
|
26
28
|
# @param logger [Logger] The logger to use for notifications.
|
27
|
-
# @see parse
|
29
|
+
# @see #parse
|
28
30
|
def initialize(file = nil, overrides = {}, logger = nil)
|
29
31
|
self.parse(file, overrides, logger)
|
30
32
|
end
|
31
33
|
|
32
34
|
# Creates a new configuration.
|
35
|
+
#
|
33
36
|
# A configuration file is a plain Ruby file with a top-level {Configuration config} object.
|
34
37
|
#
|
35
38
|
# Example:
|
@@ -65,5 +68,21 @@ module Bovem
|
|
65
68
|
|
66
69
|
self
|
67
70
|
end
|
71
|
+
|
72
|
+
# Defines a new property for the configuration
|
73
|
+
#
|
74
|
+
# @param name [Symbol] The name of the property.
|
75
|
+
# @param options [Hash] A set of options for the property. Currently, only `:default` (which holds the default value) is supported.
|
76
|
+
def self.property(name, options = {})
|
77
|
+
options = {} if !options.is_a?(::Hash)
|
78
|
+
|
79
|
+
define_method(name.to_s) do
|
80
|
+
self.instance_variable_get("@#{name}") || options[:default]
|
81
|
+
end
|
82
|
+
|
83
|
+
define_method("#{name}=") do |value|
|
84
|
+
self.instance_variable_set("@#{name}", value)
|
85
|
+
end
|
86
|
+
end
|
68
87
|
end
|
69
88
|
end
|
data/lib/bovem/version.rb
CHANGED
@@ -8,7 +8,7 @@ require "spec_helper"
|
|
8
8
|
|
9
9
|
describe Bovem::Configuration do
|
10
10
|
class BaseConfiguration < Bovem::Configuration
|
11
|
-
|
11
|
+
property :property
|
12
12
|
end
|
13
13
|
|
14
14
|
let(:log_file) { "/tmp/bovem-test-log-#{Time.now.strftime("%Y%m%d-%H:%M:%S")}" }
|
@@ -43,4 +43,19 @@ describe Bovem::Configuration do
|
|
43
43
|
File.unlink(test_prefix)
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
describe ".property" do
|
48
|
+
it "add the property to the object" do
|
49
|
+
subject = BaseConfiguration.new
|
50
|
+
|
51
|
+
expect(subject.respond_to?(:new_property)).to be_false
|
52
|
+
expect(subject.respond_to?(:new_property=)).to be_false
|
53
|
+
BaseConfiguration.property :new_property, :default => "VALUE"
|
54
|
+
expect(subject.respond_to?(:new_property)).to be_true
|
55
|
+
expect(subject.respond_to?(:new_property=)).to be_true
|
56
|
+
expect(subject.new_property).to eq("VALUE")
|
57
|
+
subject.new_property = "NEW VALUE"
|
58
|
+
expect(subject.new_property).to eq("NEW VALUE")
|
59
|
+
end
|
60
|
+
end
|
46
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bovem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -192,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
192
|
version: '0'
|
193
193
|
segments:
|
194
194
|
- 0
|
195
|
-
hash:
|
195
|
+
hash: 2994685413523034481
|
196
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
197
|
none: false
|
198
198
|
requirements:
|
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
201
|
version: '0'
|
202
202
|
segments:
|
203
203
|
- 0
|
204
|
-
hash:
|
204
|
+
hash: 2994685413523034481
|
205
205
|
requirements: []
|
206
206
|
rubyforge_project: bovem
|
207
207
|
rubygems_version: 1.8.24
|