fig_tree 0.0.1 → 0.0.2

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 359a81208b3825233a55fd631b7b4e9c00ba34451286679c5ceb2c93cc50787d
4
- data.tar.gz: 58f8342253d10c7d37575a05761b05f89d9bff3579f85ba682cc5341a0b55b29
3
+ metadata.gz: b1587ecda3a1e2b8a7c1993a2503ac43a23f8a94f9bbcdb70c19b1824dd07549
4
+ data.tar.gz: c90479e701fb69cd2c734e87fc7f111313677d461822a7cd222610ea15926ef5
5
5
  SHA512:
6
- metadata.gz: 6ec628b03063fc54940a2a6503362d4c13937541865a786f1a1197719b0b4e4e08a4eb24c07acf32cd99237010ef53b7d2247c224f7900da41567a8b414d30c4
7
- data.tar.gz: d29f30d43a4bc821da27b36c5c3c3af7e983780eb758f6baa5a55e638427a94844a2284341977e3a75d0792ab8a725cc9c80e9c20608d61e5ebf1c02bb015d08
6
+ metadata.gz: db355d8c2c40596245c6f68c5b99023bc372fa705c04f3936fd34ca55b34526539c2a87bb49afe545c075666c26caeb06264d792be064c5fd4f048fd405bb465
7
+ data.tar.gz: 6366b0a1c6be5b66e98adc2bbab97449fe88ac5f102e84e6ae21828f6db7b3d6796b6e51d619b241514db5398bf342c26f04e23dbcbb25361dc60a3c211bc17e
data/CHANGELOG.md CHANGED
@@ -7,5 +7,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
- ## [0.0.1] - 2021-02-17
10
+ ## [0.0.2] - 2021-02-17
11
11
  - Initial release.
data/fig_tree.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = 'Configuration framework for Ruby.'
13
13
  spec.homepage = ''
14
14
  spec.license = 'Apache-2.0'
15
- spec.required_ruby_version = '2.3'
15
+ spec.required_ruby_version = '>= 2.3'
16
16
 
17
17
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FigTree
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fig_tree'
4
+
5
+ # :nodoc:
6
+ class MyConfig
7
+ include FigTree
8
+
9
+ define_settings do
10
+ setting :set1
11
+ setting :set2, 'hi mom'
12
+ setting :group do
13
+ setting :set3, default_proc: proc { false }
14
+ setting :set5, (proc { 5 })
15
+ end
16
+
17
+ setting_object :listy do
18
+ setting :list1, 10
19
+ setting :list2, 5
20
+ end
21
+ end
22
+ end
23
+
24
+ describe FigTree do
25
+ it 'should configure correctly with default values' do
26
+ expect(MyConfig.config.set1).to be_nil
27
+ expect(MyConfig.config.set2).to eq('hi mom')
28
+ expect(MyConfig.config.group.set3).to eq(false)
29
+ expect(MyConfig.config.listy_objects).to be_empty
30
+ expect { MyConfig.config.blah }.to raise_error(NameError)
31
+ expect { MyConfig.config.group.set4 }.to raise_error(NameError)
32
+ end
33
+
34
+ it 'should not call the proc until it has to' do
35
+ num_calls = 0
36
+ value_proc = proc do
37
+ num_calls += 1
38
+ num_calls
39
+ end
40
+ MyConfig.define_settings do
41
+ setting :set_with_proc, default_proc: value_proc
42
+ end
43
+ expect(num_calls).to eq(0)
44
+ expect(MyConfig.config.set_with_proc).to eq(1)
45
+ # calling twice should not call the proc again
46
+ expect(MyConfig.config.set_with_proc).to eq(1)
47
+ expect(num_calls).to eq(1)
48
+ end
49
+
50
+ it "should raise error when setting configs that don't exist" do
51
+ expect { MyConfig.configure { set15('some_value') } }.to raise_error(NameError)
52
+ end
53
+
54
+ it 'should add values' do
55
+ MyConfig.configure do |config|
56
+ config.set1 = 5 # config.x syntax
57
+ set2 nil # method_missing syntax
58
+ config.group.set3 = true
59
+ end
60
+
61
+ # second configure should not blow anything away
62
+ MyConfig.configure do
63
+ listy do
64
+ list1 0
65
+ list2 1
66
+ end
67
+ listy do
68
+ list1 100
69
+ list2 200
70
+ end
71
+ end
72
+
73
+ expect(MyConfig.config.set1).to eq(5)
74
+ expect(MyConfig.config.set2).to be_nil
75
+ expect(MyConfig.config.group.set3).to eq(true)
76
+ expect(MyConfig.config.listy_objects.map(&:to_h)).
77
+ to eq([
78
+ { list1: 0, list2: 1 },
79
+ { list1: 100, list2: 200 }
80
+ ])
81
+
82
+ # test reset!
83
+ MyConfig.config.reset!
84
+ expect(MyConfig.config.set1).to be_nil
85
+ expect(MyConfig.config.set2).to eq('hi mom')
86
+ expect(MyConfig.config.group.set3).to eq(false)
87
+ expect(MyConfig.config.listy_objects).to be_empty
88
+ end
89
+
90
+ it 'should add with block syntax' do
91
+ MyConfig.configure do
92
+ group do
93
+ set5(proc { 10 })
94
+ end
95
+ end
96
+ expect(MyConfig.config.group.set5.call).to eq(10)
97
+ end
98
+
99
+ it 'should add or redefine settings' do
100
+ MyConfig.define_settings do
101
+ setting :group do
102
+ setting :set6, 15
103
+ setting :set5, (proc { 15 })
104
+ end
105
+ setting_object :notey do
106
+ setting :note_title, 'some-title'
107
+ end
108
+ end
109
+
110
+ expect(MyConfig.config.group.set6).to eq(15)
111
+ expect(MyConfig.config.group.set5.call).to eq(15)
112
+ expect(MyConfig.config.listy_objects).to be_empty
113
+ expect(MyConfig.config.notey_objects).to be_empty
114
+
115
+ MyConfig.configure do
116
+ notey do
117
+ note_title 'hi mom'
118
+ end
119
+ listy do
120
+ list1 0
121
+ end
122
+ end
123
+ expect(MyConfig.config.notey_objects.size).to eq(1)
124
+ expect(MyConfig.config.notey_objects.first.note_title).to eq('hi mom')
125
+ expect(MyConfig.config.listy_objects.size).to eq(1)
126
+ expect(MyConfig.config.listy_objects.first.list1).to eq(0)
127
+
128
+ # This should not remove any keys
129
+ MyConfig.define_settings do
130
+ setting :group do
131
+ setting :set6, 20
132
+ end
133
+ end
134
+ expect(MyConfig.config.group.set6).to eq(20)
135
+ expect(MyConfig.config.group.set5.call).to eq(15)
136
+ end
137
+
138
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fig_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-04 00:00:00.000000000 Z
11
+ date: 2021-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -144,6 +144,7 @@ files:
144
144
  - fig_tree.gemspec
145
145
  - lib/fig_tree.rb
146
146
  - lib/fig_tree/version.rb
147
+ - spec/fig_tree_spec.rb
147
148
  - spec/spec_helper.rb
148
149
  - support/flipp-logo.png
149
150
  homepage: ''
@@ -156,7 +157,7 @@ require_paths:
156
157
  - lib
157
158
  required_ruby_version: !ruby/object:Gem::Requirement
158
159
  requirements:
159
- - - '='
160
+ - - ">="
160
161
  - !ruby/object:Gem::Version
161
162
  version: '2.3'
162
163
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -170,4 +171,5 @@ signing_key:
170
171
  specification_version: 4
171
172
  summary: Configuration framework for Ruby.
172
173
  test_files:
174
+ - spec/fig_tree_spec.rb
173
175
  - spec/spec_helper.rb