squire 1.2.4 → 1.2.5

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODI1YmM1YTE1MjgwYmM3MmNkMWUyNDI1Mzg1ZDAxMWRmYzJmODEzNQ==
4
+ MDJkODhmYWNjYmIyYzNkNTUwN2RmNTNjZDFjYmY3Mzk0MDIwYjU3NA==
5
5
  data.tar.gz: !binary |-
6
- ZDQ3OTM0YWM5ZjkxMTM4NTBiZTdlYzkxY2ZlYjA2NzY5YWMwNjBjZA==
6
+ ODgxZTg2YzhjOWEyYTExMTI1YzdkZDgzODg4OTRkZTZmNGI5OGI5Nw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Njk2ODAxM2RhYTU4OTc4YmUyODIxMzhjYWI4ODc3YTRmOTdhYjQ2NGI5ZmQ3
10
- NzVmMTUxMWJmNTJmMDliMmYyNmMyYmE3NjU2Nzc2YmQ1YTI0YzBmODNmZmE0
11
- YzI5OTE4YjgxNmQ1Yjk5NDhlOThjZmU4YWFkOTExZjNlNTY0OTc=
9
+ OGRhNWMwNjgzZDljYjA3MmFlZTg3YmY1YmM0Nzk3ZDMxMjU2OGRjMmE0OWY0
10
+ YTY2MzZjN2RjNWYyNTA4NWZmODdiMjZkZTkxODk4OWZkMTRjMmMxYWNhMmQz
11
+ ZjJjZjQ2Y2Y3YWVmZmFjZTk0OWEwNTlhZDljODRkOWVmZGEyNGY=
12
12
  data.tar.gz: !binary |-
13
- ZDg3ZTFiN2E5OTA2MWE0Zjg5NzkyM2M1M2U5MzEyZTA0MDgzOGVlYTFlOWRj
14
- NGM0YzkxYzhmZTQ2N2QyMDcyMWRjNTRmZWVjNGUyYTgyNzJkNDA0M2Q3ODQ3
15
- OGFkMWRjYThiODJhNTRmYzEyZDA3NjhlYzYzMDIwODk2NDBjOTA=
13
+ ZmRlMWNjYjAzOTFmMTBlMDQ0NWIzODQwZTMyOTEyMGUzODFiOTA5MTU3Y2I2
14
+ MDQyNjZmY2MwZWZkN2U3OGMwZWRhMWY5OTM4MjI2ZTk0NWU1MTVhZDA3OTYx
15
+ YTEyNDYwMjAxZTFiMWQ3MDNhZDUzZTUwMDNjN2FkYzZkNGJmZDQ=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 1.2.5
2
+ * Use HashWithIndifferentAccess for accessing parser result
3
+ * Add better string representation of Squire::Settings
4
+
5
+ *Samuel Molnár*
6
+
1
7
  ### 1.2.4
2
8
  * Fix gemspec licence (#1)
3
9
  * Use BasicObject as clean slate for Squire::Setting
@@ -71,7 +71,7 @@ module Squire
71
71
 
72
72
  parser = Squire::Parser.of(@type)
73
73
 
74
- hash = parser.parse(source)
74
+ hash = parser.parse(source).with_indifferent_access
75
75
 
76
76
  if base_namespace
77
77
  hash.except(base_namespace).each do |key, values|
@@ -1,8 +1,6 @@
1
1
  module Squire
2
- class Settings < BasicObject
3
- include ::Kernel
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 in '#{key}' in '#{@path}'.")
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, result)
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
@@ -1,3 +1,3 @@
1
1
  module Squire
2
- VERSION = '1.2.4'
2
+ VERSION = '1.2.5'
3
3
  end
data/lib/squire.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'active_support/concern'
2
2
  require 'active_support/core_ext/hash/except'
3
+ require 'active_support/core_ext/hash/indifferent_access'
3
4
  require 'squire/core_ext/hash/deep_merge'
4
5
  require 'squire/version'
5
6
  require 'squire/exceptions'
@@ -36,5 +36,7 @@ describe Squire::Base do
36
36
 
37
37
  subject.a.should eql(1)
38
38
  subject.b.should eql(2)
39
+
40
+ expect { subject.c }.to raise_error(Squire::MissingSettingError, /Missing setting 'c' in 'test'/)
39
41
  end
40
42
  end
@@ -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 = 'Your configuration squire.'
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
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-28 00:00:00.000000000 Z
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: Your configuration squire.
83
+ description: Squire handles your configuration by common config DSL.
84
84
  email:
85
85
  - molnar.samuel@gmail.com
86
86
  executables: []