settingson 1.7.7 → 1.7.8

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: 2e0abff7e29154b68e0008ebc83fb512c6418042
4
- data.tar.gz: 3e3318ab67f0b95e0fc8a8dfce9f27f41753e286
3
+ metadata.gz: b98735a13bd6244ec4b786e599451dac575e78c1
4
+ data.tar.gz: b6adcb94c38670e3c4a92aa79d4890af389f6bd8
5
5
  SHA512:
6
- metadata.gz: bdc095b96d9ef702464c42ec7f65fba3a8f5a86f9d45870eb4bf1d621f7b8ff4824b4ff83828fd3c6613c4a4d15c83f4a31de23b7ee6935112b7d22a44a1c22b
7
- data.tar.gz: 3ce8f5406467feee5fc043ce643d6f47050c848e9af166075eb6559527971183aa69924dcb1f79bbea307960a6cdba806f1d551cf25e0656734afa63a99c8dc2
6
+ metadata.gz: f00b4aa3f2f5cbafb4aed5544a1c35e53cf13652c3e91bf97bcfe90a762e3ce9c499aaf55c21c7be38394562c1d7777dfd23b586a9009fb75487b3e8e36d8ba9
7
+ data.tar.gz: 880af88d221a90cfe86e8cb3a1118065d981e3ee84f16a0da9097425eaa85389b957ec5da34dd869f0dfb619daf890cebcbbb5f2d56ba5b63c3b0c8ea6810d58
data/.travis.yml CHANGED
@@ -7,10 +7,12 @@ script: "bundle exec rspec && bundle exec codeclimate-test-reporter"
7
7
 
8
8
  rvm:
9
9
  - 2.2.2
10
+ - 2.4.1
10
11
 
11
12
  gemfile:
12
13
  - gemfiles/4.2.gemfile
13
14
  - gemfiles/5.0.gemfile
15
+ - gemfiles/5.1.gemfile
14
16
 
15
17
  env:
16
18
  - CODECLIMATE_REPO_TOKEN=620b22e287791de2c9f8a522182ddf57098302ff8958768f8192eaaa7d8a685d
data/Appraisals CHANGED
@@ -5,3 +5,7 @@ end
5
5
  appraise "5.0" do
6
6
  gem "rails", "~> 5.0.0"
7
7
  end
8
+
9
+ appraise "5.1" do
10
+ gem "rails", "~> 5.1.0"
11
+ end
@@ -19,15 +19,20 @@ module Settingson::Base
19
19
  @_settings
20
20
  end
21
21
 
22
- # Settings.defaults do |settings|
23
- # settings.server.host = 'host'
24
- # settings.server.port = 80
22
+ # Settings.defaults do |default|
23
+ # default.server.host = 'host'
24
+ # default.server.port = 80
25
25
  # end
26
26
  def defaults
27
- return unless block_given?
28
- Rails.application.config.after_initialize do
29
- yield Settingson::Defaults.new( klass: self )
27
+ @__defaults = Settingson::Default.new( klass: self )
28
+
29
+ if block_given?
30
+ Rails.application.config.after_initialize do
31
+ yield @__defaults
32
+ end
30
33
  end
34
+
35
+ @__defaults
31
36
  end
32
37
 
33
38
  # Settings.from_hash('smtp.host' => 'host')
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: ../
2
+ remote: ..
3
3
  specs:
4
- settingson (1.7.6)
4
+ settingson (1.7.8)
5
5
  rails (>= 4.0)
6
6
 
7
7
  GEM
@@ -162,4 +162,4 @@ DEPENDENCIES
162
162
  sqlite3
163
163
 
164
164
  BUNDLED WITH
165
- 1.12.5
165
+ 1.15.4
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: ../
2
+ remote: ..
3
3
  specs:
4
- settingson (1.7.6)
4
+ settingson (1.7.8)
5
5
  rails (>= 4.0)
6
6
 
7
7
  GEM
@@ -169,4 +169,4 @@ DEPENDENCIES
169
169
  sqlite3
170
170
 
171
171
  BUNDLED WITH
172
- 1.12.5
172
+ 1.15.4
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "codeclimate-test-reporter", group: :test, require: nil
6
+ gem "rails", "~> 5.1.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,175 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ settingson (1.7.8)
5
+ rails (>= 4.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.1.4)
11
+ actionpack (= 5.1.4)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (~> 0.6.1)
14
+ actionmailer (5.1.4)
15
+ actionpack (= 5.1.4)
16
+ actionview (= 5.1.4)
17
+ activejob (= 5.1.4)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.1.4)
21
+ actionview (= 5.1.4)
22
+ activesupport (= 5.1.4)
23
+ rack (~> 2.0)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.1.4)
28
+ activesupport (= 5.1.4)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.1.4)
34
+ activesupport (= 5.1.4)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.1.4)
37
+ activesupport (= 5.1.4)
38
+ activerecord (5.1.4)
39
+ activemodel (= 5.1.4)
40
+ activesupport (= 5.1.4)
41
+ arel (~> 8.0)
42
+ activesupport (5.1.4)
43
+ concurrent-ruby (~> 1.0, >= 1.0.2)
44
+ i18n (~> 0.7)
45
+ minitest (~> 5.1)
46
+ tzinfo (~> 1.1)
47
+ appraisal (2.2.0)
48
+ bundler
49
+ rake
50
+ thor (>= 0.14.0)
51
+ arel (8.0.0)
52
+ builder (3.2.3)
53
+ codeclimate-test-reporter (1.0.8)
54
+ simplecov (<= 0.13)
55
+ concurrent-ruby (1.0.5)
56
+ crass (1.0.2)
57
+ database_cleaner (1.6.1)
58
+ diff-lcs (1.3)
59
+ docile (1.1.5)
60
+ erubi (1.7.0)
61
+ faker (1.8.4)
62
+ i18n (~> 0.5)
63
+ globalid (0.4.0)
64
+ activesupport (>= 4.2.0)
65
+ i18n (0.9.0)
66
+ concurrent-ruby (~> 1.0)
67
+ json (2.1.0)
68
+ loofah (2.1.1)
69
+ crass (~> 1.0.2)
70
+ nokogiri (>= 1.5.9)
71
+ mail (2.6.6)
72
+ mime-types (>= 1.16, < 4)
73
+ method_source (0.9.0)
74
+ mime-types (3.1)
75
+ mime-types-data (~> 3.2015)
76
+ mime-types-data (3.2016.0521)
77
+ mini_portile2 (2.3.0)
78
+ minitest (5.10.3)
79
+ nio4r (2.1.0)
80
+ nokogiri (1.8.1)
81
+ mini_portile2 (~> 2.3.0)
82
+ rack (2.0.3)
83
+ rack-test (0.7.0)
84
+ rack (>= 1.0, < 3)
85
+ rails (5.1.4)
86
+ actioncable (= 5.1.4)
87
+ actionmailer (= 5.1.4)
88
+ actionpack (= 5.1.4)
89
+ actionview (= 5.1.4)
90
+ activejob (= 5.1.4)
91
+ activemodel (= 5.1.4)
92
+ activerecord (= 5.1.4)
93
+ activesupport (= 5.1.4)
94
+ bundler (>= 1.3.0)
95
+ railties (= 5.1.4)
96
+ sprockets-rails (>= 2.0.0)
97
+ rails-dom-testing (2.0.3)
98
+ activesupport (>= 4.2.0)
99
+ nokogiri (>= 1.6)
100
+ rails-dummy (0.0.4)
101
+ rails
102
+ rails-html-sanitizer (1.0.3)
103
+ loofah (~> 2.0)
104
+ railties (5.1.4)
105
+ actionpack (= 5.1.4)
106
+ activesupport (= 5.1.4)
107
+ method_source
108
+ rake (>= 0.8.7)
109
+ thor (>= 0.18.1, < 2.0)
110
+ rake (12.1.0)
111
+ rspec (3.6.0)
112
+ rspec-core (~> 3.6.0)
113
+ rspec-expectations (~> 3.6.0)
114
+ rspec-mocks (~> 3.6.0)
115
+ rspec-core (3.6.0)
116
+ rspec-support (~> 3.6.0)
117
+ rspec-expectations (3.6.0)
118
+ diff-lcs (>= 1.2.0, < 2.0)
119
+ rspec-support (~> 3.6.0)
120
+ rspec-mocks (3.6.0)
121
+ diff-lcs (>= 1.2.0, < 2.0)
122
+ rspec-support (~> 3.6.0)
123
+ rspec-rails (3.6.1)
124
+ actionpack (>= 3.0)
125
+ activesupport (>= 3.0)
126
+ railties (>= 3.0)
127
+ rspec-core (~> 3.6.0)
128
+ rspec-expectations (~> 3.6.0)
129
+ rspec-mocks (~> 3.6.0)
130
+ rspec-support (~> 3.6.0)
131
+ rspec-support (3.6.0)
132
+ simplecov (0.13.0)
133
+ docile (~> 1.1.0)
134
+ json (>= 1.8, < 3)
135
+ simplecov-html (~> 0.10.0)
136
+ simplecov-html (0.10.2)
137
+ spring (2.0.2)
138
+ activesupport (>= 4.2)
139
+ spring-commands-rspec (1.0.4)
140
+ spring (>= 0.9.1)
141
+ sprockets (3.7.1)
142
+ concurrent-ruby (~> 1.0)
143
+ rack (> 1, < 3)
144
+ sprockets-rails (3.2.1)
145
+ actionpack (>= 4.0)
146
+ activesupport (>= 4.0)
147
+ sprockets (>= 3.0.0)
148
+ sqlite3 (1.3.13)
149
+ thor (0.20.0)
150
+ thread_safe (0.3.6)
151
+ tzinfo (1.2.3)
152
+ thread_safe (~> 0.1)
153
+ websocket-driver (0.6.5)
154
+ websocket-extensions (>= 0.1.0)
155
+ websocket-extensions (0.1.2)
156
+
157
+ PLATFORMS
158
+ ruby
159
+
160
+ DEPENDENCIES
161
+ appraisal
162
+ bundler (>= 1.6)
163
+ codeclimate-test-reporter
164
+ database_cleaner
165
+ faker
166
+ rails (~> 5.1.0)
167
+ rails-dummy
168
+ rspec (~> 3.5)
169
+ rspec-rails (~> 3.5)
170
+ settingson!
171
+ spring-commands-rspec
172
+ sqlite3
173
+
174
+ BUNDLED WITH
175
+ 1.15.4
data/lib/settingson.rb CHANGED
@@ -5,6 +5,6 @@ module Settingson
5
5
  if defined?(Rails)
6
6
  require 'settingson/engine'
7
7
  require 'settingson/store'
8
- require 'settingson/defaults'
8
+ require 'settingson/default'
9
9
  end
10
10
  end
@@ -0,0 +1,11 @@
1
+ class Settingson::Default
2
+ require 'settingson/default/store'
3
+
4
+ def initialize(klass:)
5
+ @__klass = klass
6
+ end # initialize
7
+
8
+ def method_missing(symbol, *args)
9
+ Settingson::Default::Store.new( klass: @__klass ).send(symbol, *args)
10
+ end # method_missing
11
+ end
@@ -0,0 +1,127 @@
1
+ class Settingson::Default::Store
2
+
3
+ @@__defaults = {}
4
+
5
+ def initialize(klass:, path: nil)
6
+ @__klass = klass
7
+ @__path = path
8
+ end
9
+
10
+ def to_h
11
+ @@_defaults
12
+ end
13
+
14
+ def to_ary
15
+ @@__defaults.to_a
16
+ end
17
+
18
+ def method_missing(symbol, *args)
19
+ __debug
20
+ __debug("from\n\t#{caller[1..@__klass.configure.trace].join("\n\t")}") if
21
+ @__klass.configure.trace > 0
22
+
23
+ __references_action(symbol, *args) or __rescue_action(symbol.to_s, *args)
24
+ # __rescue_action(symbol.to_s, *args)
25
+ end # method_missing
26
+
27
+ def __references_action(symbol, *args)
28
+ # Proxy pass only one method
29
+ # return nil
30
+ # return nil unless ['model_name', 'to_model'].include?(symbol.to_s)
31
+ if @__klass and @__klass.respond_to?(symbol)
32
+ __debug("#{@__klass.to_s} know what to do with #{symbol}")
33
+ @__klass.send(symbol, *args)
34
+ end
35
+ end
36
+
37
+ def __rescue_action(key, *args)
38
+ __debug("key: #{key}:#{key.class} args: #{args}:#{args.class} " +
39
+ "path: '#{@__path}'")
40
+ case key
41
+ when '[]' # object reference[, with :field]
42
+ __debug("reference '#{args}'")
43
+ __get( __with_reference(args[0], args[1]) )
44
+ when '[]=' # object reference setter
45
+ __debug("reference setter '#{args}'")
46
+ if args.size == 3 # [@setting, :key]= form
47
+ __set( __with_reference(args[0], args[1]), args[2] )
48
+ else # [@settings]= form
49
+ __set( __with_reference(args.first), args.last )
50
+ end
51
+ when /(.+)=/ # setter
52
+ __debug("set '#{$1}' args '#{args.first}'")
53
+ __set($1, args.first)
54
+ else # returns result or self
55
+ __debug("get '#{key}'")
56
+ __get(key)
57
+ end
58
+ end
59
+
60
+ protected
61
+ # TODO: move all methods to support class
62
+ def __debug(message="")
63
+ return unless @__klass.configure.debug
64
+ message = sprintf("%s#%20s: %s",
65
+ self.class.name,
66
+ caller_locations.first.label,
67
+ message)
68
+ Rails.logger.debug(message)
69
+ end
70
+
71
+ def __set(key, value)
72
+ @@__defaults[_search_path(key)] = value
73
+ @__path = ''
74
+ value
75
+ end
76
+
77
+ def __get(key)
78
+ __update_search_path(key)
79
+ @@__defaults[@__path] || self
80
+ end
81
+
82
+ # @profile = Profile.first # any ActiveRecord::Base object
83
+ # Settings[@profile].some.host = 'value'
84
+ def __with_reference(key, field=nil)
85
+ case key
86
+ when String
87
+ key
88
+ when Symbol
89
+ key.to_s
90
+ when ActiveRecord::Base
91
+ @__reference = key
92
+ if field.nil?
93
+ class_name = __underscore(key.class)
94
+ ref_id = __reference_id(key)
95
+ "#{class_name}_#{ref_id || 'new'}"
96
+ else
97
+ key.send(field.to_sym)
98
+ end
99
+ else
100
+ raise ArgumentError.new(
101
+ 'String/Symbol/ActiveRecord::Base variable required'
102
+ )
103
+ end
104
+ end
105
+
106
+ def __underscore(camel_cased_word)
107
+ word = camel_cased_word.to_s.dup
108
+ word.gsub!(/::/, '_')
109
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
110
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
111
+ word.tr!('-', '_')
112
+ word.downcase!
113
+ word
114
+ end
115
+
116
+ def __reference_id(key)
117
+ key.try(:to_key).try(:join, '_') || key.id
118
+ end
119
+
120
+ def _search_path(key)
121
+ [@__path, key].compact.join('.')
122
+ end
123
+
124
+ def __update_search_path(key)
125
+ @__path = _search_path(key)
126
+ end
127
+ end
@@ -101,7 +101,8 @@ class Settingson::Store
101
101
  __update_search_path(key)
102
102
  result = __cached_or_default_value(@__path)
103
103
 
104
- if result.is_a?(ActiveRecord::RecordNotFound)
104
+ if result.is_a?(ActiveRecord::RecordNotFound) or
105
+ result.is_a?(Settingson::Default::Store)
105
106
  __debug("return self with path: #{@__path}")
106
107
  self
107
108
  else
@@ -155,8 +156,9 @@ class Settingson::Store
155
156
  def __cached_or_default_value(key)
156
157
  result = __cached_value(key)
157
158
 
158
- if ! @__defaults and result.is_a?(ActiveRecord::RecordNotFound)
159
- __cached_value('__defaults.' + key)
159
+ if result.is_a?(ActiveRecord::RecordNotFound)
160
+ __debug("looking in #{@__klass.name}.defaults[#{key}]")
161
+ @__klass.defaults[key]
160
162
  else
161
163
  result
162
164
  end
@@ -1,3 +1,3 @@
1
1
  module Settingson
2
- VERSION = "1.7.7"
2
+ VERSION = "1.7.8"
3
3
  end
@@ -34,4 +34,6 @@ Rails.application.configure do
34
34
 
35
35
  # Raises error for missing translations
36
36
  # config.action_view.raise_on_missing_translations = true
37
+
38
+ config.cache_store = :memory_store, { size: 8.megabytes }
37
39
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Settingson::Default do
4
+
5
+ it 'not raises errors with empty block' do
6
+ expect{ Settings.defaults {} }.to_not raise_error
7
+ end
8
+
9
+ it 'returns value for given key' do
10
+ word = Faker::Lorem.word
11
+ h = Settings.defaults{|s| s.cached_key = word}
12
+ expect( h['cached_key'] ).to eq(word)
13
+ end
14
+
15
+ it 'returns value for given key #2' do
16
+ word = Faker::Lorem.word
17
+ h = Settings.defaults do |s|
18
+ s.cached_key1 = word
19
+ s.cached.key2 = word
20
+ end
21
+ expect( h['cached.key2'] ).to eq(word)
22
+ end
23
+
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settingson
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.7
4
+ version: 1.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - dan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-16 00:00:00.000000000 Z
11
+ date: 2017-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -173,11 +173,14 @@ files:
173
173
  - gemfiles/4.2.gemfile.lock
174
174
  - gemfiles/5.0.gemfile
175
175
  - gemfiles/5.0.gemfile.lock
176
+ - gemfiles/5.1.gemfile
177
+ - gemfiles/5.1.gemfile.lock
176
178
  - lib/generators/settingson/settingson_generator.rb
177
179
  - lib/generators/settingson/templates/migrations/rename_name_to_key_on_settings.rb
178
180
  - lib/settingson.rb
179
181
  - lib/settingson/config.rb
180
- - lib/settingson/defaults.rb
182
+ - lib/settingson/default.rb
183
+ - lib/settingson/default/store.rb
181
184
  - lib/settingson/engine.rb
182
185
  - lib/settingson/store.rb
183
186
  - lib/settingson/utils.rb
@@ -231,6 +234,7 @@ files:
231
234
  - spec/dummy/public/500.html
232
235
  - spec/dummy/public/favicon.ico
233
236
  - spec/models/settings_spec.rb
237
+ - spec/models/settingson/defaults_spec.rb
234
238
  - spec/spec_helper.rb
235
239
  homepage: https://github.com/daanforever/settingson
236
240
  licenses:
@@ -306,4 +310,5 @@ test_files:
306
310
  - spec/dummy/public/500.html
307
311
  - spec/dummy/public/favicon.ico
308
312
  - spec/models/settings_spec.rb
313
+ - spec/models/settingson/defaults_spec.rb
309
314
  - spec/spec_helper.rb
@@ -1,12 +0,0 @@
1
- class Settingson::Defaults
2
- def initialize(klass:)
3
- @__klass = klass
4
- @__path = '__defaults'
5
- end # initialize
6
-
7
- def method_missing(symbol, *args)
8
- Settingson::Store.new(
9
- klass: @__klass, path: @__path, defaults: true
10
- ).send(symbol, *args)
11
- end # method_missing
12
- end