active_setting 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rb +5 -0
- data/lib/active_setting/loader.rb +2 -0
- data/lib/active_setting/setting.rb +4 -3
- data/lib/active_setting/version.rb +1 -1
- data/spec/loader_spec.rb +1 -1
- data/spec/setting_spec.rb +102 -52
- data/spec/settings.yml +1 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/coverage_loader.rb +3 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36b602a83a7757e51d0a71e2aae6b673f5725db0
|
4
|
+
data.tar.gz: 6d5334e081cc113f666f52a351f7cde871dc2bbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff7d50bdfda6ed4902c7558495afd66a57820cd7a522299c132b70da259f047bff484c30205a1df91eaddd318953e8ae6d3596af3bb02cd2b17bb2797cbd3956
|
7
|
+
data.tar.gz: 61f7b32df626bc0bb834e26fd0892387aa9f0f8239481f47bb2add5ae55631e0908e6245582e0da15d8e07dd68aa77888d29a5580be92f2c38f242e96f7c28a8
|
data/CHANGELOG.rb
ADDED
@@ -38,6 +38,7 @@ module ActiveSetting
|
|
38
38
|
def load_settings
|
39
39
|
settings_config.each do |category_name, settings|
|
40
40
|
settings.each do |setting_name, values|
|
41
|
+
values ||= {}
|
41
42
|
attrs = values.merge(
|
42
43
|
data_type: values['type'],
|
43
44
|
category: category_name,
|
@@ -51,6 +52,7 @@ module ActiveSetting
|
|
51
52
|
def build_hash
|
52
53
|
settings_config.map.with_object({}) do |(category_name, settings), hash|
|
53
54
|
settings.each do |setting_name, values|
|
55
|
+
values ||= {}
|
54
56
|
attrs = values.merge(
|
55
57
|
data_type: values['type'],
|
56
58
|
category: category_name,
|
@@ -80,7 +80,8 @@ module ActiveSetting
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def value
|
83
|
-
v = raw_value
|
83
|
+
v = raw_value
|
84
|
+
v = default if raw_value.nil?
|
84
85
|
|
85
86
|
# TODO: WHY IS the first line here
|
86
87
|
return nil if v.nil?
|
@@ -121,8 +122,8 @@ module ActiveSetting
|
|
121
122
|
end
|
122
123
|
|
123
124
|
def csv_value(v)
|
124
|
-
return v if v.
|
125
|
-
v.split(',').map(&:strip).map { |e| Setting.convert_value(e, subtype) }
|
125
|
+
return v if v.is_a?(Array) # e.g. default = []
|
126
|
+
v.to_s.split(',').map(&:strip).map { |e| Setting.convert_value(e, subtype) }
|
126
127
|
end
|
127
128
|
end
|
128
129
|
end
|
data/spec/loader_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe ActiveSetting::Loader do
|
|
6
6
|
it 'should parse a settings file to get settings' do
|
7
7
|
ActiveSetting::Loader.load_settings(config_filename)
|
8
8
|
settings = ActiveSetting::Setting.registered_settings
|
9
|
-
settings.keys.
|
9
|
+
expect(settings.keys).to include :maximum_percent
|
10
10
|
end
|
11
11
|
|
12
12
|
context 'when building a settings hash from the settings file' do
|
data/spec/setting_spec.rb
CHANGED
@@ -1,80 +1,130 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveSetting::Setting, 'with types/casting' do
|
4
|
-
|
5
|
-
s = ActiveSetting::Setting.new(data_type: :integer, raw_value: '6')
|
6
|
-
s.value.should eq 6
|
4
|
+
subject { ActiveSetting::Setting.new(data_type: data_type, raw_value: raw_value).value }
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
context 'when integer 6' do
|
7
|
+
let(:data_type) { :integer }
|
8
|
+
let(:raw_value) { '6' }
|
9
|
+
it { is_expected.to eq 6 }
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
context 'when decimal 7.6' do
|
13
|
+
let(:data_type) { :decimal }
|
14
|
+
let(:raw_value) { '7.6' }
|
15
|
+
it { is_expected.to eq 7.6 }
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
context 'when symbol hello' do
|
19
|
+
let(:data_type) { :symbol }
|
20
|
+
let(:raw_value) { 'hello' }
|
21
|
+
it { is_expected.to eq :hello }
|
16
22
|
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
context 'when unspecified hello' do
|
25
|
+
let(:data_type) { nil }
|
26
|
+
let(:raw_value) { 'hello' }
|
27
|
+
it { is_expected.to eq 'hello' }
|
28
|
+
end
|
21
29
|
|
22
|
-
|
23
|
-
|
30
|
+
context 'when boolean' do
|
31
|
+
let(:data_type) { :boolean }
|
24
32
|
|
25
|
-
|
26
|
-
|
33
|
+
context 'when 0' do
|
34
|
+
let(:raw_value) { '0' }
|
35
|
+
it { is_expected.to be false }
|
36
|
+
end
|
27
37
|
|
28
|
-
|
29
|
-
|
38
|
+
context 'when false' do
|
39
|
+
let(:raw_value) { 'false' }
|
40
|
+
it { is_expected.to be false }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when boolean false' do
|
44
|
+
let(:raw_value) { false }
|
45
|
+
it { is_expected.to be false }
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when 1' do
|
49
|
+
let(:raw_value) { '1' }
|
50
|
+
it { is_expected.to be true }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when true' do
|
54
|
+
let(:raw_value) { 'true' }
|
55
|
+
it { is_expected.to be true }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when boolean true' do
|
59
|
+
let(:raw_value) { true }
|
60
|
+
it { is_expected.to be true }
|
61
|
+
end
|
30
62
|
end
|
31
63
|
|
32
|
-
|
33
|
-
|
34
|
-
|
64
|
+
context 'when csv' do
|
65
|
+
subject { ActiveSetting::Setting.new(default: default, data_type: data_type, subtype: subtype, raw_value: raw_value).value }
|
66
|
+
let(:default) { [] }
|
67
|
+
let(:data_type) { :csv }
|
68
|
+
context 'when array of integers' do
|
69
|
+
let(:subtype) { :integer }
|
70
|
+
let(:raw_value) { '1,2,3' }
|
71
|
+
it { is_expected.to eq [1, 2, 3] }
|
72
|
+
|
73
|
+
context 'when raw value is type cast' do
|
74
|
+
let(:raw_value) { 1 }
|
75
|
+
it { is_expected.to eq [1] }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when no value, so default' do
|
79
|
+
let(:raw_value) { nil }
|
80
|
+
it { is_expected.to eq [] }
|
35
81
|
|
36
|
-
|
37
|
-
|
82
|
+
context 'when default a non empty array' do
|
83
|
+
let(:default) { [1, 2] }
|
84
|
+
it { is_expected.to eq [1, 2] }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when array of symbols' do
|
90
|
+
let(:subtype) { :symbol }
|
91
|
+
let(:raw_value) { 'first, second' } # deliberate spacing
|
92
|
+
it { is_expected.to eq [:first, :second] }
|
93
|
+
end
|
94
|
+
end
|
38
95
|
|
39
|
-
|
40
|
-
|
96
|
+
context 'when hash' do
|
97
|
+
let(:data_type) { :hash }
|
98
|
+
let(:raw_value) { 'a:1 , b : 2' } # deliberate spacing
|
99
|
+
it { is_expected.to eq(a: '1', b: '2') }
|
41
100
|
end
|
42
101
|
end
|
43
102
|
|
44
103
|
describe ActiveSetting::Setting, 'when having options' do
|
45
|
-
|
46
|
-
|
47
|
-
|
104
|
+
context 'with regular options' do
|
105
|
+
subject { ActiveSetting::Setting.new(options: 'easy normal hard').options }
|
106
|
+
it { is_expected.to eq %w(easy normal hard) }
|
48
107
|
end
|
49
108
|
|
50
|
-
|
51
|
-
first
|
52
|
-
second
|
53
|
-
|
54
|
-
|
109
|
+
context 'calculating objects from collection' do
|
110
|
+
let(:first) { double(id: '1', name: 'First') }
|
111
|
+
let(:second) { double(id: '2', name: 'Second') }
|
112
|
+
subject { ActiveSetting::Setting.new.objects_from_collection([first, second], :name, :id) }
|
113
|
+
it { is_expected.to eq [%w(First 1), %w(Second 2)] }
|
55
114
|
end
|
56
115
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def self.objects
|
62
|
-
@objects ||= []
|
63
|
-
end
|
116
|
+
context 'with object options' do
|
117
|
+
before do
|
118
|
+
stub_const 'Model', double(all: objects)
|
119
|
+
end
|
64
120
|
|
65
|
-
|
66
|
-
|
67
|
-
|
121
|
+
subject { ActiveSetting::Setting.new(object_options: 'Model.all id name').options }
|
122
|
+
let(:objects) { [] }
|
123
|
+
it { is_expected.to eq [] }
|
68
124
|
|
69
|
-
|
70
|
-
|
71
|
-
|
125
|
+
context 'when objects exist' do
|
126
|
+
let(:objects) { [double(id: 1, name: 'First')] }
|
127
|
+
it { is_expected.to eq [[1, 'First']] }
|
72
128
|
end
|
73
|
-
|
74
|
-
s = ActiveSetting::Setting.new(object_options: 'Model.all id name')
|
75
|
-
s.options.should eq []
|
76
|
-
first = double(id: 1, name: 'First')
|
77
|
-
Model.objects = [first]
|
78
|
-
s.options.should eq [[1, 'First']]
|
79
129
|
end
|
80
130
|
end
|
data/spec/settings.yml
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -12,7 +12,7 @@ require 'support/coverage_loader'
|
|
12
12
|
require 'active_setting'
|
13
13
|
|
14
14
|
RSpec.configure do |config|
|
15
|
-
config.
|
15
|
+
config.raise_errors_for_deprecations!
|
16
16
|
config.run_all_when_everything_filtered = true
|
17
17
|
config.filter_run :focus
|
18
18
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
MINIMUM_COVERAGE =
|
1
|
+
MINIMUM_COVERAGE = 97
|
2
2
|
|
3
3
|
unless ENV['COVERAGE'] == 'off'
|
4
4
|
require 'simplecov'
|
@@ -18,8 +18,9 @@ unless ENV['COVERAGE'] == 'off'
|
|
18
18
|
SimpleCov.at_exit do
|
19
19
|
SimpleCov.result.format!
|
20
20
|
percent = SimpleCov.result.covered_percent
|
21
|
+
puts "Coverage is #{"%.2f" % percent}%"
|
21
22
|
unless percent >= MINIMUM_COVERAGE
|
22
|
-
puts "Coverage must be above #{MINIMUM_COVERAGE}
|
23
|
+
puts "Coverage must be above #{MINIMUM_COVERAGE}%"
|
23
24
|
Kernel.exit(1)
|
24
25
|
end
|
25
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_setting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Noack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- ".ruby-style.yml"
|
136
136
|
- ".ruby-version"
|
137
137
|
- ".travis.yml"
|
138
|
+
- CHANGELOG.rb
|
138
139
|
- Gemfile
|
139
140
|
- README.md
|
140
141
|
- Rakefile
|
@@ -168,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
169
|
version: '0'
|
169
170
|
requirements: []
|
170
171
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.4.8
|
172
173
|
signing_key:
|
173
174
|
specification_version: 4
|
174
175
|
summary: Store active_settings of various data types
|