bovem 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bovem (0.5.0)
4
+ bovem (0.6.0)
5
5
  lazier (~> 1.0)
6
6
  rainbow (~> 1.1.0)
7
7
 
@@ -31,6 +31,4 @@ Gem::Specification.new do |gem|
31
31
  gem.add_development_dependency("yard", "~> 0.8.0")
32
32
  gem.add_development_dependency("redcarpet", "~> 2.1.0")
33
33
  gem.add_development_dependency("github-markup", "~> 0.7.0")
34
- end
35
-
36
-
34
+ end
@@ -8,7 +8,7 @@ require "rainbow"
8
8
  require "logger"
9
9
  require "lazier"
10
10
 
11
- #Lazier.load!
11
+ Lazier.load!(:object)
12
12
 
13
13
  require "bovem/version" if !defined?(Bovem::Version)
14
14
  require "bovem/errors"
@@ -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 `attr_accessor` methods.
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
- # attr_accessor :property
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
@@ -14,7 +14,7 @@ module Bovem
14
14
  MAJOR = 0
15
15
 
16
16
  # The minor version.
17
- MINOR = 5
17
+ MINOR = 6
18
18
 
19
19
  # The patch version.
20
20
  PATCH = 0
@@ -8,7 +8,7 @@ require "spec_helper"
8
8
 
9
9
  describe Bovem::Configuration do
10
10
  class BaseConfiguration < Bovem::Configuration
11
- attr_accessor :property
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.5.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: -3168302242936700516
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: -3168302242936700516
204
+ hash: 2994685413523034481
205
205
  requirements: []
206
206
  rubyforge_project: bovem
207
207
  rubygems_version: 1.8.24