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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d905b6225a4c743215e6f56aee659741c83b4c7
4
- data.tar.gz: 6956767bbc1c17ad2a3584fa8ea1790de01467f2
3
+ metadata.gz: 36b602a83a7757e51d0a71e2aae6b673f5725db0
4
+ data.tar.gz: 6d5334e081cc113f666f52a351f7cde871dc2bbc
5
5
  SHA512:
6
- metadata.gz: 3e098853466eceae1c2314305c732de831e83fe1f3eec075b6cb8fc86c6503833c98bd7e424edb9fe6faa4b74d872055026d7d307fabadc4521551d7cd1b79bf
7
- data.tar.gz: 9cff93d5a668cae4d80f6107c38db9d69be6612411f54824b420512a524acc02028fb4635ead2c1b68f341c4fc79e8933d91cd4861ff8b3a520adc938d8ff615
6
+ metadata.gz: ff7d50bdfda6ed4902c7558495afd66a57820cd7a522299c132b70da259f047bff484c30205a1df91eaddd318953e8ae6d3596af3bb02cd2b17bb2797cbd3956
7
+ data.tar.gz: 61f7b32df626bc0bb834e26fd0892387aa9f0f8239481f47bb2add5ae55631e0908e6245582e0da15d8e07dd68aa77888d29a5580be92f2c38f242e96f7c28a8
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ * Support raw values being non string
@@ -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 || default
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.empty? # e.g. default = []
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
@@ -1,3 +1,3 @@
1
1
  module ActiveSetting
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -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.should include :maximum_percent
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
@@ -1,80 +1,130 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveSetting::Setting, 'with types/casting' do
4
- it 'should handle basic types and casting' do
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
- s = ActiveSetting::Setting.new(data_type: :decimal, raw_value: '7.6')
9
- s.value.should eq 7.6
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
- s = ActiveSetting::Setting.new(data_type: :symbol, raw_value: 'hello')
12
- s.value.should eq :hello
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
- s = ActiveSetting::Setting.new(raw_value: 'hello')
15
- s.value.should eq 'hello'
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
- it 'should handle boolean types' do
19
- s = ActiveSetting::Setting.new(data_type: :boolean, raw_value: '0')
20
- s.value.should be false
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
- s = ActiveSetting::Setting.new(data_type: :boolean, raw_value: 'false')
23
- s.value.should be false
30
+ context 'when boolean' do
31
+ let(:data_type) { :boolean }
24
32
 
25
- s = ActiveSetting::Setting.new(data_type: :boolean, raw_value: '1')
26
- s.value.should be true
33
+ context 'when 0' do
34
+ let(:raw_value) { '0' }
35
+ it { is_expected.to be false }
36
+ end
27
37
 
28
- s = ActiveSetting::Setting.new(data_type: :boolean, raw_value: 'true')
29
- s.value.should be true
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
- it 'should handle multi value types including subvalue types and handle spacing' do
33
- s = ActiveSetting::Setting.new(data_type: :csv, subtype: :integer, raw_value: '1,2,3')
34
- s.value.should eq [1, 2, 3]
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
- s = ActiveSetting::Setting.new(data_type: :csv, subtype: :symbol, raw_value: 'first, second')
37
- s.value.should eq [:first, :second]
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
- s = ActiveSetting::Setting.new(data_type: :hash, raw_value: 'a:1 , b : 2')
40
- s.value.should eq(a: '1', b: '2')
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
- it 'should format the options in the right type' do
46
- s = ActiveSetting::Setting.new(options: 'easy normal hard')
47
- s.options.should eq %w(easy normal hard)
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
- it 'should format the options by key,value when object options' do
51
- first = double(id: '1', name: 'First')
52
- second = double(id: '2', name: 'Second')
53
- s = ActiveSetting::Setting.new
54
- s.objects_from_collection([first, second], :name, :id).should eq [%w(First 1), %w(Second 2)]
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
- it 'should not cache object options' do
58
- class Model
59
- attr_accessor :id, :name
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
- def self.all
66
- objects
67
- end
121
+ subject { ActiveSetting::Setting.new(object_options: 'Model.all id name').options }
122
+ let(:objects) { [] }
123
+ it { is_expected.to eq [] }
68
124
 
69
- class << self
70
- attr_writer :objects
71
- end
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
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  settings:
3
3
  general_category:
4
+ minimalist:
4
5
  maximum_percent:
5
6
  default: 50
6
7
  type: integer
@@ -12,7 +12,7 @@ require 'support/coverage_loader'
12
12
  require 'active_setting'
13
13
 
14
14
  RSpec.configure do |config|
15
- config.treat_symbols_as_metadata_keys_with_true_values = true
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 = 90
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}%. It is #{"%.2f" % percent}%"
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.1
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-06-17 00:00:00.000000000 Z
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.5.1
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