iron-settings 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +6 -0
- data/README.rdoc +11 -2
- data/Version.txt +1 -1
- data/lib/iron-settings.rb +1 -0
- data/lib/iron/settings.rb +1 -0
- data/lib/iron/settings/class_level.rb +1 -0
- data/lib/iron/settings/cursor.rb +15 -1
- data/spec/settings/cursor_spec.rb +15 -0
- data/spec/spec_helper.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ff3ceb048486b314e176cb0a6c7733f2bf50c3c
|
4
|
+
data.tar.gz: 706357ea7822e59582d9e049d9c3cd4ab8e28ac4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f28ef71c9d33a6fa6b3c3dcfa212b049585dd584c9e4861de91f0f590e173df8745ba64a08d2d8c2a63784c94b91f6fc2a472e0ca6e7231b73d0aec953692d8f
|
7
|
+
data.tar.gz: fdb528d297029f1684812e8dc76dd5daa99b859d5d5e65cb827cb979ca86888a4e5302fa0cab6591d1366d2c823e7185a48a691079c375d8dea75d8a50e6ead0
|
data/History.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 1.0.4 / 2018-01-03
|
2
|
+
|
3
|
+
* Update docs to show group setting for static values
|
4
|
+
* Add Cursor#entry_values to allow getting a hash of all values for a given group
|
5
|
+
* Update Cursor#method_missing to return false if querying for a missing entry
|
6
|
+
|
1
7
|
== 1.0.3 / 2015-01-27
|
2
8
|
|
3
9
|
* Update to use new 1.2 version of iron-extensions and add dependency on iron-dsl gem
|
data/README.rdoc
CHANGED
@@ -72,6 +72,10 @@ configuration info.
|
|
72
72
|
class_settings(:file => '~/.mytool') do
|
73
73
|
string('api_key')
|
74
74
|
string('base_path', '~')
|
75
|
+
group('options') do
|
76
|
+
bool('debug', false)
|
77
|
+
bool('verbose', false)
|
78
|
+
end
|
75
79
|
end
|
76
80
|
|
77
81
|
def initialize
|
@@ -85,10 +89,15 @@ configuration info.
|
|
85
89
|
|
86
90
|
end
|
87
91
|
|
88
|
-
Now, your users could create a .mytool file like so
|
92
|
+
Now, your users could create a .mytool file like so. Notice how there are no equals signs,
|
93
|
+
and the group settings can be accessed in a block:
|
89
94
|
|
90
95
|
api_key '1234ASDF'
|
91
96
|
base_path '~/code'
|
97
|
+
options do
|
98
|
+
debug true
|
99
|
+
verbose true
|
100
|
+
end
|
92
101
|
|
93
102
|
On calling MyTool.settings, this file would be loaded and override the settings defaults.
|
94
103
|
|
@@ -127,7 +136,7 @@ RVM users can skip the sudo:
|
|
127
136
|
|
128
137
|
Then use
|
129
138
|
|
130
|
-
require 'iron
|
139
|
+
require 'iron-settings'
|
131
140
|
|
132
141
|
to require the library code.
|
133
142
|
|
data/Version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.4
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'iron/settings'
|
data/lib/iron/settings.rb
CHANGED
data/lib/iron/settings/cursor.rb
CHANGED
@@ -29,6 +29,14 @@ class Settings
|
|
29
29
|
keys
|
30
30
|
end
|
31
31
|
|
32
|
+
# Returns a hash of all entry keys to their values at the cursor's current
|
33
|
+
# position, and optionally including all child keys. If the cursor is at
|
34
|
+
# a sub-group node, keys will be relative to that node.
|
35
|
+
def entry_values(include_all = true)
|
36
|
+
keys = entry_keys(include_all)
|
37
|
+
keys.convert_to_hash {|k| item_value(find_item(k)) }
|
38
|
+
end
|
39
|
+
|
32
40
|
# Returns all group keys
|
33
41
|
def group_keys(include_all = false)
|
34
42
|
keys = @group.entries(include_all).collect {|e| e.key }
|
@@ -93,7 +101,13 @@ class Settings
|
|
93
101
|
item = @group.find_item(method)
|
94
102
|
if item.nil?
|
95
103
|
# Unknown item name, whoops.
|
96
|
-
|
104
|
+
if query
|
105
|
+
# Querying for existence of key is fine if it's missing
|
106
|
+
return false
|
107
|
+
else
|
108
|
+
# Setting or getting, GTFO
|
109
|
+
raise RuntimeError.new("Unknown settings group or entry '#{method}' for settings path #{@group.key}")
|
110
|
+
end
|
97
111
|
|
98
112
|
elsif item.group?
|
99
113
|
if query
|
@@ -91,5 +91,20 @@ describe Settings::Cursor do
|
|
91
91
|
it 'should eval lambda defaults in the context of the root cursor' do
|
92
92
|
CursorTest.settings.top.middle.bottom.lamby.should == 6
|
93
93
|
end
|
94
|
+
|
95
|
+
it 'should return a hash of keys to vals' do
|
96
|
+
CursorTest.settings.invalid_default = 'hi'
|
97
|
+
CursorTest.settings.entry_values.should == {
|
98
|
+
'val1' => 5,
|
99
|
+
'val2' => nil,
|
100
|
+
'top.middle.bottom.lamby' => 6,
|
101
|
+
'top.middle.bottom.leaf' => nil,
|
102
|
+
'invalid_default' => 'hi'
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should return false on interrogating a missing key' do
|
107
|
+
CursorTest.settings.bob?.should be_false
|
108
|
+
end
|
94
109
|
|
95
110
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -38,6 +38,11 @@ RSpec.configure do |config|
|
|
38
38
|
config.color = true
|
39
39
|
config.add_formatter 'documentation'
|
40
40
|
config.backtrace_exclusion_patterns = [/rspec/]
|
41
|
+
# Allow us to use: it '...', :focus do ... end
|
42
|
+
# rather than needing: it '...', :focus => true do ... end
|
43
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
44
|
+
# If everything is filtered, run everything - used if no :focus element is present
|
45
|
+
config.run_all_when_everything_filtered = true
|
41
46
|
end
|
42
47
|
|
43
48
|
module SpecHelper
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Morris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iron-extensions
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- README.rdoc
|
67
67
|
- Version.txt
|
68
68
|
- db/settings_migration.rb
|
69
|
+
- lib/iron-settings.rb
|
69
70
|
- lib/iron/rake_loader.rb
|
70
71
|
- lib/iron/settings.rb
|
71
72
|
- lib/iron/settings/builder.rb
|