squire 1.2.4 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +6 -0
- data/lib/squire/configuration.rb +1 -1
- data/lib/squire/settings.rb +19 -8
- data/lib/squire/version.rb +1 -1
- data/lib/squire.rb +1 -0
- data/spec/squire/base_spec.rb +2 -0
- data/spec/squire/settings_spec.rb +30 -1
- data/squire.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDJkODhmYWNjYmIyYzNkNTUwN2RmNTNjZDFjYmY3Mzk0MDIwYjU3NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODgxZTg2YzhjOWEyYTExMTI1YzdkZDgzODg4OTRkZTZmNGI5OGI5Nw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGRhNWMwNjgzZDljYjA3MmFlZTg3YmY1YmM0Nzk3ZDMxMjU2OGRjMmE0OWY0
|
10
|
+
YTY2MzZjN2RjNWYyNTA4NWZmODdiMjZkZTkxODk4OWZkMTRjMmMxYWNhMmQz
|
11
|
+
ZjJjZjQ2Y2Y3YWVmZmFjZTk0OWEwNTlhZDljODRkOWVmZGEyNGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmRlMWNjYjAzOTFmMTBlMDQ0NWIzODQwZTMyOTEyMGUzODFiOTA5MTU3Y2I2
|
14
|
+
MDQyNjZmY2MwZWZkN2U3OGMwZWRhMWY5OTM4MjI2ZTk0NWU1MTVhZDA3OTYx
|
15
|
+
YTEyNDYwMjAxZTFiMWQ3MDNhZDUzZTUwMDNjN2FkYzZkNGJmZDQ=
|
data/CHANGELOG.md
CHANGED
data/lib/squire/configuration.rb
CHANGED
data/lib/squire/settings.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Squire
|
2
|
-
class Settings
|
3
|
-
|
4
|
-
|
5
|
-
RESERVED = [:get_value, :set_value, :define_key_accessor, :to_hash]
|
2
|
+
class Settings
|
3
|
+
RESERVED = [:get_value, :set_value, :define_key_accessor, :to_hash, :to_s, :[]]
|
6
4
|
|
7
5
|
##
|
8
6
|
# Creates new settings with +path+ and +parent+.
|
@@ -62,7 +60,7 @@ module Squire
|
|
62
60
|
value = get_value(key)
|
63
61
|
|
64
62
|
if value.nil?
|
65
|
-
raise MissingSettingError.new("Missing setting
|
63
|
+
raise MissingSettingError.new("Missing setting '#{key}' in '#{@path}'.")
|
66
64
|
end
|
67
65
|
|
68
66
|
value
|
@@ -85,6 +83,7 @@ module Squire
|
|
85
83
|
# ...
|
86
84
|
# end
|
87
85
|
def get_value(key, &block)
|
86
|
+
key = key.to_sym
|
88
87
|
value = @table[key]
|
89
88
|
|
90
89
|
if block_given?
|
@@ -118,17 +117,29 @@ module Squire
|
|
118
117
|
result
|
119
118
|
end
|
120
119
|
|
120
|
+
##
|
121
|
+
# Shows string representation of settings
|
122
|
+
def to_s
|
123
|
+
"#<#{self.class.name} #{@table.map { |key, value| "#{key}=#{value}"}.join(', ')}>"
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# Access +key+ from table directly
|
128
|
+
def [](key)
|
129
|
+
get_value(key)
|
130
|
+
end
|
131
|
+
|
121
132
|
##
|
122
133
|
# Loads new settings from provided +hash+.
|
123
134
|
def self.from_hash(hash, parent = nil)
|
124
|
-
result = Settings.new
|
135
|
+
result = Settings.new(parent)
|
125
136
|
|
126
137
|
hash.each_pair do |key, value|
|
127
138
|
if value.is_a? ::Hash
|
128
|
-
value = from_hash(value,
|
139
|
+
value = from_hash(value, key)
|
129
140
|
end
|
130
141
|
|
131
|
-
result.set_value(key, value)
|
142
|
+
result.set_value(key.to_sym, value)
|
132
143
|
end
|
133
144
|
|
134
145
|
result
|
data/lib/squire/version.rb
CHANGED
data/lib/squire.rb
CHANGED
data/spec/squire/base_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
# :TODO: Refactor redundant usage of subject
|
4
|
+
|
3
5
|
describe Squire::Settings do
|
4
6
|
subject { Squire::Settings }
|
5
7
|
|
@@ -57,7 +59,34 @@ describe Squire::Settings do
|
|
57
59
|
it 'should raise error when setting is missing' do
|
58
60
|
config = subject.new
|
59
61
|
|
60
|
-
expect { config.a }.to raise_error(Squire::MissingSettingError)
|
62
|
+
expect { config.a }.to raise_error(Squire::MissingSettingError, /Missing setting 'a'/)
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#to_s' do
|
66
|
+
it 'should convert settings to string representation' do
|
67
|
+
config = subject.new
|
68
|
+
|
69
|
+
config.a = 1
|
70
|
+
config.b = 2
|
71
|
+
|
72
|
+
config.nested do |nested|
|
73
|
+
nested.c = 3
|
74
|
+
end
|
75
|
+
|
76
|
+
config.to_s.should eql('#<Squire::Settings a=1, b=2, nested=#<Squire::Settings c=3>>')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#[]' do
|
81
|
+
it 'should allow accesing keys in hash manner' do
|
82
|
+
config = subject.new
|
83
|
+
|
84
|
+
config.a = 1
|
85
|
+
|
86
|
+
config[:a].should eql(1)
|
87
|
+
config['a'].should eql(1)
|
88
|
+
config[:b].should be_nil
|
89
|
+
end
|
61
90
|
end
|
62
91
|
|
63
92
|
describe '#to_hash' do
|
data/squire.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Squire::VERSION
|
9
9
|
gem.authors = ['Samuel Molnar']
|
10
10
|
gem.email = ['molnar.samuel@gmail.com']
|
11
|
-
gem.description = '
|
11
|
+
gem.description = 'Squire handles your configuration by common config DSL.'
|
12
12
|
gem.summary = 'Squire handles your configuration per class/file by common config DSL and extensible source formats.'
|
13
13
|
gem.homepage = 'https://github.com/smolnar/squire'
|
14
14
|
gem.license = 'MIT'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Molnar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: Squire handles your configuration by common config DSL.
|
84
84
|
email:
|
85
85
|
- molnar.samuel@gmail.com
|
86
86
|
executables: []
|