settingson 1.7.8 → 1.7.10
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 +4 -4
- data/README.md +14 -0
- data/app/models/concerns/settingson/base.rb +2 -2
- data/gemfiles/4.2.gemfile.lock +67 -71
- data/gemfiles/5.0.gemfile.lock +77 -81
- data/gemfiles/5.1.gemfile.lock +28 -35
- data/lib/settingson.rb +0 -1
- data/lib/settingson/config.rb +1 -0
- data/lib/settingson/store.rb +26 -21
- data/lib/settingson/store/default.rb +25 -0
- data/lib/settingson/store/general.rb +3 -0
- data/lib/settingson/version.rb +1 -1
- data/settingson.gemspec +0 -1
- data/spec/dummy/config/initializers/settingson.rb +1 -0
- data/spec/models/settingson/defaults_spec.rb +13 -1
- metadata +4 -17
- data/lib/settingson/default/store.rb +0 -127
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f386d06c5ca9c9f4bc53680acde702b3c220b9dc
|
|
4
|
+
data.tar.gz: 0dd5979d1f284281186bf6bfb5c53fe4df11cd4a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 28731bc9f03371ff13bfaa45dcf3ab0bea0b896d532607c55ec3df27aeae7cbcdf254714f13bb71e4eb58aac45cf357d1f55f8db3adf7a6076606e63b1924e3d
|
|
7
|
+
data.tar.gz: 7b901c14b6d6d31409fe334db1fd7266ebad1b5206527f45f681cd4ae0a845261ad2a7d215af470fe40a16e4456ed87e7925c82c8e6bfbd450bde1b5fb7295b8
|
data/README.md
CHANGED
|
@@ -48,6 +48,7 @@ as the generator will have created a migration file (if your ORM supports them).
|
|
|
48
48
|
shell commands:
|
|
49
49
|
```console
|
|
50
50
|
bin/rails g settingson Settings
|
|
51
|
+
bin/rails db:migrate
|
|
51
52
|
```
|
|
52
53
|
|
|
53
54
|
code:
|
|
@@ -128,6 +129,19 @@ Settings.server.smtp.host # => 'host'
|
|
|
128
129
|
Settings.server.smtp.port # => 25
|
|
129
130
|
```
|
|
130
131
|
|
|
132
|
+
## Debug and testings
|
|
133
|
+
in config/initializers/settingson.rb
|
|
134
|
+
```ruby
|
|
135
|
+
|
|
136
|
+
if Rails.env.development?
|
|
137
|
+
Settings.configure.debug = true
|
|
138
|
+
Settings.configure.trace = 3
|
|
139
|
+
Settings.configure.cache.enabled = false (default: true)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
Caching is disabled by default only in test environment.
|
|
143
|
+
```
|
|
144
|
+
|
|
131
145
|
## Contributing
|
|
132
146
|
|
|
133
147
|
1. Fork it ( https://github.com/daanforever/settingson/fork )
|
|
@@ -24,7 +24,7 @@ module Settingson::Base
|
|
|
24
24
|
# default.server.port = 80
|
|
25
25
|
# end
|
|
26
26
|
def defaults
|
|
27
|
-
@__defaults = Settingson::Default.new( klass: self )
|
|
27
|
+
@__defaults = Settingson::Store::Default.new( klass: self )
|
|
28
28
|
|
|
29
29
|
if block_given?
|
|
30
30
|
Rails.application.config.after_initialize do
|
|
@@ -58,7 +58,7 @@ module Settingson::Base
|
|
|
58
58
|
def method_missing(symbol, *args)
|
|
59
59
|
super
|
|
60
60
|
rescue NameError, NoMethodError
|
|
61
|
-
Settingson::Store.new(klass: self).send(symbol, *args)
|
|
61
|
+
Settingson::Store::General.new(klass: self).send(symbol, *args)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
end # module ClassMethods
|
data/gemfiles/4.2.gemfile.lock
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ..
|
|
3
3
|
specs:
|
|
4
|
-
settingson (1.7.
|
|
4
|
+
settingson (1.7.9)
|
|
5
5
|
rails (>= 4.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actionmailer (4.2.
|
|
11
|
-
actionpack (= 4.2.
|
|
12
|
-
actionview (= 4.2.
|
|
13
|
-
activejob (= 4.2.
|
|
10
|
+
actionmailer (4.2.10)
|
|
11
|
+
actionpack (= 4.2.10)
|
|
12
|
+
actionview (= 4.2.10)
|
|
13
|
+
activejob (= 4.2.10)
|
|
14
14
|
mail (~> 2.5, >= 2.5.4)
|
|
15
15
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
16
|
-
actionpack (4.2.
|
|
17
|
-
actionview (= 4.2.
|
|
18
|
-
activesupport (= 4.2.
|
|
16
|
+
actionpack (4.2.10)
|
|
17
|
+
actionview (= 4.2.10)
|
|
18
|
+
activesupport (= 4.2.10)
|
|
19
19
|
rack (~> 1.6)
|
|
20
20
|
rack-test (~> 0.6.2)
|
|
21
21
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
22
22
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
23
|
-
actionview (4.2.
|
|
24
|
-
activesupport (= 4.2.
|
|
23
|
+
actionview (4.2.10)
|
|
24
|
+
activesupport (= 4.2.10)
|
|
25
25
|
builder (~> 3.1)
|
|
26
26
|
erubis (~> 2.7.0)
|
|
27
27
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
28
28
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
29
|
-
activejob (4.2.
|
|
30
|
-
activesupport (= 4.2.
|
|
29
|
+
activejob (4.2.10)
|
|
30
|
+
activesupport (= 4.2.10)
|
|
31
31
|
globalid (>= 0.3.0)
|
|
32
|
-
activemodel (4.2.
|
|
33
|
-
activesupport (= 4.2.
|
|
32
|
+
activemodel (4.2.10)
|
|
33
|
+
activesupport (= 4.2.10)
|
|
34
34
|
builder (~> 3.1)
|
|
35
|
-
activerecord (4.2.
|
|
36
|
-
activemodel (= 4.2.
|
|
37
|
-
activesupport (= 4.2.
|
|
35
|
+
activerecord (4.2.10)
|
|
36
|
+
activemodel (= 4.2.10)
|
|
37
|
+
activesupport (= 4.2.10)
|
|
38
38
|
arel (~> 6.0)
|
|
39
|
-
activesupport (4.2.
|
|
39
|
+
activesupport (4.2.10)
|
|
40
40
|
i18n (~> 0.7)
|
|
41
41
|
minitest (~> 5.1)
|
|
42
42
|
thread_safe (~> 0.3, >= 0.3.4)
|
|
@@ -50,40 +50,41 @@ GEM
|
|
|
50
50
|
codeclimate-test-reporter (1.0.8)
|
|
51
51
|
simplecov (<= 0.13)
|
|
52
52
|
concurrent-ruby (1.0.5)
|
|
53
|
-
|
|
53
|
+
crass (1.0.3)
|
|
54
|
+
database_cleaner (1.6.2)
|
|
54
55
|
diff-lcs (1.3)
|
|
55
56
|
docile (1.1.5)
|
|
56
57
|
erubis (2.7.0)
|
|
57
|
-
faker (1.
|
|
58
|
+
faker (1.8.4)
|
|
58
59
|
i18n (~> 0.5)
|
|
59
|
-
globalid (0.4.
|
|
60
|
+
globalid (0.4.1)
|
|
60
61
|
activesupport (>= 4.2.0)
|
|
61
|
-
i18n (0.
|
|
62
|
+
i18n (0.9.1)
|
|
63
|
+
concurrent-ruby (~> 1.0)
|
|
62
64
|
json (2.1.0)
|
|
63
|
-
loofah (2.
|
|
65
|
+
loofah (2.1.1)
|
|
66
|
+
crass (~> 1.0.2)
|
|
64
67
|
nokogiri (>= 1.5.9)
|
|
65
|
-
mail (2.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
mini_portile2 (~> 2.1.0)
|
|
74
|
-
rack (1.6.5)
|
|
68
|
+
mail (2.7.0)
|
|
69
|
+
mini_mime (>= 0.1.1)
|
|
70
|
+
mini_mime (1.0.0)
|
|
71
|
+
mini_portile2 (2.3.0)
|
|
72
|
+
minitest (5.10.3)
|
|
73
|
+
nokogiri (1.8.1)
|
|
74
|
+
mini_portile2 (~> 2.3.0)
|
|
75
|
+
rack (1.6.8)
|
|
75
76
|
rack-test (0.6.3)
|
|
76
77
|
rack (>= 1.0)
|
|
77
|
-
rails (4.2.
|
|
78
|
-
actionmailer (= 4.2.
|
|
79
|
-
actionpack (= 4.2.
|
|
80
|
-
actionview (= 4.2.
|
|
81
|
-
activejob (= 4.2.
|
|
82
|
-
activemodel (= 4.2.
|
|
83
|
-
activerecord (= 4.2.
|
|
84
|
-
activesupport (= 4.2.
|
|
78
|
+
rails (4.2.10)
|
|
79
|
+
actionmailer (= 4.2.10)
|
|
80
|
+
actionpack (= 4.2.10)
|
|
81
|
+
actionview (= 4.2.10)
|
|
82
|
+
activejob (= 4.2.10)
|
|
83
|
+
activemodel (= 4.2.10)
|
|
84
|
+
activerecord (= 4.2.10)
|
|
85
|
+
activesupport (= 4.2.10)
|
|
85
86
|
bundler (>= 1.3.0, < 2.0)
|
|
86
|
-
railties (= 4.2.
|
|
87
|
+
railties (= 4.2.10)
|
|
87
88
|
sprockets-rails
|
|
88
89
|
rails-deprecated_sanitizer (1.0.3)
|
|
89
90
|
activesupport (>= 4.2.0.alpha)
|
|
@@ -95,53 +96,49 @@ GEM
|
|
|
95
96
|
rails
|
|
96
97
|
rails-html-sanitizer (1.0.3)
|
|
97
98
|
loofah (~> 2.0)
|
|
98
|
-
railties (4.2.
|
|
99
|
-
actionpack (= 4.2.
|
|
100
|
-
activesupport (= 4.2.
|
|
99
|
+
railties (4.2.10)
|
|
100
|
+
actionpack (= 4.2.10)
|
|
101
|
+
activesupport (= 4.2.10)
|
|
101
102
|
rake (>= 0.8.7)
|
|
102
103
|
thor (>= 0.18.1, < 2.0)
|
|
103
|
-
rake (12.
|
|
104
|
-
rspec (3.
|
|
105
|
-
rspec-core (~> 3.
|
|
106
|
-
rspec-expectations (~> 3.
|
|
107
|
-
rspec-mocks (~> 3.
|
|
108
|
-
rspec-core (3.
|
|
109
|
-
rspec-support (~> 3.
|
|
110
|
-
rspec-expectations (3.
|
|
104
|
+
rake (12.3.0)
|
|
105
|
+
rspec (3.7.0)
|
|
106
|
+
rspec-core (~> 3.7.0)
|
|
107
|
+
rspec-expectations (~> 3.7.0)
|
|
108
|
+
rspec-mocks (~> 3.7.0)
|
|
109
|
+
rspec-core (3.7.0)
|
|
110
|
+
rspec-support (~> 3.7.0)
|
|
111
|
+
rspec-expectations (3.7.0)
|
|
111
112
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
112
|
-
rspec-support (~> 3.
|
|
113
|
-
rspec-mocks (3.
|
|
113
|
+
rspec-support (~> 3.7.0)
|
|
114
|
+
rspec-mocks (3.7.0)
|
|
114
115
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
115
|
-
rspec-support (~> 3.
|
|
116
|
-
rspec-rails (3.
|
|
116
|
+
rspec-support (~> 3.7.0)
|
|
117
|
+
rspec-rails (3.7.2)
|
|
117
118
|
actionpack (>= 3.0)
|
|
118
119
|
activesupport (>= 3.0)
|
|
119
120
|
railties (>= 3.0)
|
|
120
|
-
rspec-core (~> 3.
|
|
121
|
-
rspec-expectations (~> 3.
|
|
122
|
-
rspec-mocks (~> 3.
|
|
123
|
-
rspec-support (~> 3.
|
|
124
|
-
rspec-support (3.
|
|
121
|
+
rspec-core (~> 3.7.0)
|
|
122
|
+
rspec-expectations (~> 3.7.0)
|
|
123
|
+
rspec-mocks (~> 3.7.0)
|
|
124
|
+
rspec-support (~> 3.7.0)
|
|
125
|
+
rspec-support (3.7.0)
|
|
125
126
|
simplecov (0.13.0)
|
|
126
127
|
docile (~> 1.1.0)
|
|
127
128
|
json (>= 1.8, < 3)
|
|
128
129
|
simplecov-html (~> 0.10.0)
|
|
129
|
-
simplecov-html (0.10.
|
|
130
|
-
spring (2.0.1)
|
|
131
|
-
activesupport (>= 4.2)
|
|
132
|
-
spring-commands-rspec (1.0.4)
|
|
133
|
-
spring (>= 0.9.1)
|
|
130
|
+
simplecov-html (0.10.2)
|
|
134
131
|
sprockets (3.7.1)
|
|
135
132
|
concurrent-ruby (~> 1.0)
|
|
136
133
|
rack (> 1, < 3)
|
|
137
|
-
sprockets-rails (3.2.
|
|
134
|
+
sprockets-rails (3.2.1)
|
|
138
135
|
actionpack (>= 4.0)
|
|
139
136
|
activesupport (>= 4.0)
|
|
140
137
|
sprockets (>= 3.0.0)
|
|
141
138
|
sqlite3 (1.3.13)
|
|
142
|
-
thor (0.
|
|
139
|
+
thor (0.20.0)
|
|
143
140
|
thread_safe (0.3.6)
|
|
144
|
-
tzinfo (1.2.
|
|
141
|
+
tzinfo (1.2.4)
|
|
145
142
|
thread_safe (~> 0.1)
|
|
146
143
|
|
|
147
144
|
PLATFORMS
|
|
@@ -158,7 +155,6 @@ DEPENDENCIES
|
|
|
158
155
|
rspec (~> 3.5)
|
|
159
156
|
rspec-rails (~> 3.5)
|
|
160
157
|
settingson!
|
|
161
|
-
spring-commands-rspec
|
|
162
158
|
sqlite3
|
|
163
159
|
|
|
164
160
|
BUNDLED WITH
|
data/gemfiles/5.0.gemfile.lock
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ..
|
|
3
3
|
specs:
|
|
4
|
-
settingson (1.7.
|
|
4
|
+
settingson (1.7.9)
|
|
5
5
|
rails (>= 4.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actioncable (5.0.
|
|
11
|
-
actionpack (= 5.0.
|
|
10
|
+
actioncable (5.0.6)
|
|
11
|
+
actionpack (= 5.0.6)
|
|
12
12
|
nio4r (>= 1.2, < 3.0)
|
|
13
13
|
websocket-driver (~> 0.6.1)
|
|
14
|
-
actionmailer (5.0.
|
|
15
|
-
actionpack (= 5.0.
|
|
16
|
-
actionview (= 5.0.
|
|
17
|
-
activejob (= 5.0.
|
|
14
|
+
actionmailer (5.0.6)
|
|
15
|
+
actionpack (= 5.0.6)
|
|
16
|
+
actionview (= 5.0.6)
|
|
17
|
+
activejob (= 5.0.6)
|
|
18
18
|
mail (~> 2.5, >= 2.5.4)
|
|
19
19
|
rails-dom-testing (~> 2.0)
|
|
20
|
-
actionpack (5.0.
|
|
21
|
-
actionview (= 5.0.
|
|
22
|
-
activesupport (= 5.0.
|
|
20
|
+
actionpack (5.0.6)
|
|
21
|
+
actionview (= 5.0.6)
|
|
22
|
+
activesupport (= 5.0.6)
|
|
23
23
|
rack (~> 2.0)
|
|
24
24
|
rack-test (~> 0.6.3)
|
|
25
25
|
rails-dom-testing (~> 2.0)
|
|
26
26
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
27
|
-
actionview (5.0.
|
|
28
|
-
activesupport (= 5.0.
|
|
27
|
+
actionview (5.0.6)
|
|
28
|
+
activesupport (= 5.0.6)
|
|
29
29
|
builder (~> 3.1)
|
|
30
30
|
erubis (~> 2.7.0)
|
|
31
31
|
rails-dom-testing (~> 2.0)
|
|
32
32
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
33
|
-
activejob (5.0.
|
|
34
|
-
activesupport (= 5.0.
|
|
33
|
+
activejob (5.0.6)
|
|
34
|
+
activesupport (= 5.0.6)
|
|
35
35
|
globalid (>= 0.3.6)
|
|
36
|
-
activemodel (5.0.
|
|
37
|
-
activesupport (= 5.0.
|
|
38
|
-
activerecord (5.0.
|
|
39
|
-
activemodel (= 5.0.
|
|
40
|
-
activesupport (= 5.0.
|
|
36
|
+
activemodel (5.0.6)
|
|
37
|
+
activesupport (= 5.0.6)
|
|
38
|
+
activerecord (5.0.6)
|
|
39
|
+
activemodel (= 5.0.6)
|
|
40
|
+
activesupport (= 5.0.6)
|
|
41
41
|
arel (~> 7.0)
|
|
42
|
-
activesupport (5.0.
|
|
42
|
+
activesupport (5.0.6)
|
|
43
43
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
44
44
|
i18n (~> 0.7)
|
|
45
45
|
minitest (~> 5.1)
|
|
@@ -53,103 +53,100 @@ GEM
|
|
|
53
53
|
codeclimate-test-reporter (1.0.8)
|
|
54
54
|
simplecov (<= 0.13)
|
|
55
55
|
concurrent-ruby (1.0.5)
|
|
56
|
-
|
|
56
|
+
crass (1.0.3)
|
|
57
|
+
database_cleaner (1.6.2)
|
|
57
58
|
diff-lcs (1.3)
|
|
58
59
|
docile (1.1.5)
|
|
59
60
|
erubis (2.7.0)
|
|
60
|
-
faker (1.
|
|
61
|
+
faker (1.8.4)
|
|
61
62
|
i18n (~> 0.5)
|
|
62
|
-
globalid (0.4.
|
|
63
|
+
globalid (0.4.1)
|
|
63
64
|
activesupport (>= 4.2.0)
|
|
64
|
-
i18n (0.
|
|
65
|
+
i18n (0.9.1)
|
|
66
|
+
concurrent-ruby (~> 1.0)
|
|
65
67
|
json (2.1.0)
|
|
66
|
-
loofah (2.
|
|
68
|
+
loofah (2.1.1)
|
|
69
|
+
crass (~> 1.0.2)
|
|
67
70
|
nokogiri (>= 1.5.9)
|
|
68
|
-
mail (2.
|
|
69
|
-
|
|
70
|
-
method_source (0.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
mini_portile2 (~> 2.1.0)
|
|
79
|
-
rack (2.0.1)
|
|
71
|
+
mail (2.7.0)
|
|
72
|
+
mini_mime (>= 0.1.1)
|
|
73
|
+
method_source (0.9.0)
|
|
74
|
+
mini_mime (1.0.0)
|
|
75
|
+
mini_portile2 (2.3.0)
|
|
76
|
+
minitest (5.10.3)
|
|
77
|
+
nio4r (2.1.0)
|
|
78
|
+
nokogiri (1.8.1)
|
|
79
|
+
mini_portile2 (~> 2.3.0)
|
|
80
|
+
rack (2.0.3)
|
|
80
81
|
rack-test (0.6.3)
|
|
81
82
|
rack (>= 1.0)
|
|
82
|
-
rails (5.0.
|
|
83
|
-
actioncable (= 5.0.
|
|
84
|
-
actionmailer (= 5.0.
|
|
85
|
-
actionpack (= 5.0.
|
|
86
|
-
actionview (= 5.0.
|
|
87
|
-
activejob (= 5.0.
|
|
88
|
-
activemodel (= 5.0.
|
|
89
|
-
activerecord (= 5.0.
|
|
90
|
-
activesupport (= 5.0.
|
|
91
|
-
bundler (>= 1.3.0
|
|
92
|
-
railties (= 5.0.
|
|
83
|
+
rails (5.0.6)
|
|
84
|
+
actioncable (= 5.0.6)
|
|
85
|
+
actionmailer (= 5.0.6)
|
|
86
|
+
actionpack (= 5.0.6)
|
|
87
|
+
actionview (= 5.0.6)
|
|
88
|
+
activejob (= 5.0.6)
|
|
89
|
+
activemodel (= 5.0.6)
|
|
90
|
+
activerecord (= 5.0.6)
|
|
91
|
+
activesupport (= 5.0.6)
|
|
92
|
+
bundler (>= 1.3.0)
|
|
93
|
+
railties (= 5.0.6)
|
|
93
94
|
sprockets-rails (>= 2.0.0)
|
|
94
|
-
rails-dom-testing (2.0.
|
|
95
|
-
activesupport (>= 4.2.0
|
|
96
|
-
nokogiri (
|
|
95
|
+
rails-dom-testing (2.0.3)
|
|
96
|
+
activesupport (>= 4.2.0)
|
|
97
|
+
nokogiri (>= 1.6)
|
|
97
98
|
rails-dummy (0.0.4)
|
|
98
99
|
rails
|
|
99
100
|
rails-html-sanitizer (1.0.3)
|
|
100
101
|
loofah (~> 2.0)
|
|
101
|
-
railties (5.0.
|
|
102
|
-
actionpack (= 5.0.
|
|
103
|
-
activesupport (= 5.0.
|
|
102
|
+
railties (5.0.6)
|
|
103
|
+
actionpack (= 5.0.6)
|
|
104
|
+
activesupport (= 5.0.6)
|
|
104
105
|
method_source
|
|
105
106
|
rake (>= 0.8.7)
|
|
106
107
|
thor (>= 0.18.1, < 2.0)
|
|
107
|
-
rake (12.
|
|
108
|
-
rspec (3.
|
|
109
|
-
rspec-core (~> 3.
|
|
110
|
-
rspec-expectations (~> 3.
|
|
111
|
-
rspec-mocks (~> 3.
|
|
112
|
-
rspec-core (3.
|
|
113
|
-
rspec-support (~> 3.
|
|
114
|
-
rspec-expectations (3.
|
|
108
|
+
rake (12.3.0)
|
|
109
|
+
rspec (3.7.0)
|
|
110
|
+
rspec-core (~> 3.7.0)
|
|
111
|
+
rspec-expectations (~> 3.7.0)
|
|
112
|
+
rspec-mocks (~> 3.7.0)
|
|
113
|
+
rspec-core (3.7.0)
|
|
114
|
+
rspec-support (~> 3.7.0)
|
|
115
|
+
rspec-expectations (3.7.0)
|
|
115
116
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
116
|
-
rspec-support (~> 3.
|
|
117
|
-
rspec-mocks (3.
|
|
117
|
+
rspec-support (~> 3.7.0)
|
|
118
|
+
rspec-mocks (3.7.0)
|
|
118
119
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
119
|
-
rspec-support (~> 3.
|
|
120
|
-
rspec-rails (3.
|
|
120
|
+
rspec-support (~> 3.7.0)
|
|
121
|
+
rspec-rails (3.7.2)
|
|
121
122
|
actionpack (>= 3.0)
|
|
122
123
|
activesupport (>= 3.0)
|
|
123
124
|
railties (>= 3.0)
|
|
124
|
-
rspec-core (~> 3.
|
|
125
|
-
rspec-expectations (~> 3.
|
|
126
|
-
rspec-mocks (~> 3.
|
|
127
|
-
rspec-support (~> 3.
|
|
128
|
-
rspec-support (3.
|
|
125
|
+
rspec-core (~> 3.7.0)
|
|
126
|
+
rspec-expectations (~> 3.7.0)
|
|
127
|
+
rspec-mocks (~> 3.7.0)
|
|
128
|
+
rspec-support (~> 3.7.0)
|
|
129
|
+
rspec-support (3.7.0)
|
|
129
130
|
simplecov (0.13.0)
|
|
130
131
|
docile (~> 1.1.0)
|
|
131
132
|
json (>= 1.8, < 3)
|
|
132
133
|
simplecov-html (~> 0.10.0)
|
|
133
|
-
simplecov-html (0.10.
|
|
134
|
-
spring (2.0.1)
|
|
135
|
-
activesupport (>= 4.2)
|
|
136
|
-
spring-commands-rspec (1.0.4)
|
|
137
|
-
spring (>= 0.9.1)
|
|
134
|
+
simplecov-html (0.10.2)
|
|
138
135
|
sprockets (3.7.1)
|
|
139
136
|
concurrent-ruby (~> 1.0)
|
|
140
137
|
rack (> 1, < 3)
|
|
141
|
-
sprockets-rails (3.2.
|
|
138
|
+
sprockets-rails (3.2.1)
|
|
142
139
|
actionpack (>= 4.0)
|
|
143
140
|
activesupport (>= 4.0)
|
|
144
141
|
sprockets (>= 3.0.0)
|
|
145
142
|
sqlite3 (1.3.13)
|
|
146
|
-
thor (0.
|
|
143
|
+
thor (0.20.0)
|
|
147
144
|
thread_safe (0.3.6)
|
|
148
|
-
tzinfo (1.2.
|
|
145
|
+
tzinfo (1.2.4)
|
|
149
146
|
thread_safe (~> 0.1)
|
|
150
147
|
websocket-driver (0.6.5)
|
|
151
148
|
websocket-extensions (>= 0.1.0)
|
|
152
|
-
websocket-extensions (0.1.
|
|
149
|
+
websocket-extensions (0.1.3)
|
|
153
150
|
|
|
154
151
|
PLATFORMS
|
|
155
152
|
ruby
|
|
@@ -165,7 +162,6 @@ DEPENDENCIES
|
|
|
165
162
|
rspec (~> 3.5)
|
|
166
163
|
rspec-rails (~> 3.5)
|
|
167
164
|
settingson!
|
|
168
|
-
spring-commands-rspec
|
|
169
165
|
sqlite3
|
|
170
166
|
|
|
171
167
|
BUNDLED WITH
|
data/gemfiles/5.1.gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ..
|
|
3
3
|
specs:
|
|
4
|
-
settingson (1.7.
|
|
4
|
+
settingson (1.7.9)
|
|
5
5
|
rails (>= 4.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
@@ -53,34 +53,32 @@ GEM
|
|
|
53
53
|
codeclimate-test-reporter (1.0.8)
|
|
54
54
|
simplecov (<= 0.13)
|
|
55
55
|
concurrent-ruby (1.0.5)
|
|
56
|
-
crass (1.0.
|
|
57
|
-
database_cleaner (1.6.
|
|
56
|
+
crass (1.0.3)
|
|
57
|
+
database_cleaner (1.6.2)
|
|
58
58
|
diff-lcs (1.3)
|
|
59
59
|
docile (1.1.5)
|
|
60
60
|
erubi (1.7.0)
|
|
61
61
|
faker (1.8.4)
|
|
62
62
|
i18n (~> 0.5)
|
|
63
|
-
globalid (0.4.
|
|
63
|
+
globalid (0.4.1)
|
|
64
64
|
activesupport (>= 4.2.0)
|
|
65
|
-
i18n (0.9.
|
|
65
|
+
i18n (0.9.1)
|
|
66
66
|
concurrent-ruby (~> 1.0)
|
|
67
67
|
json (2.1.0)
|
|
68
68
|
loofah (2.1.1)
|
|
69
69
|
crass (~> 1.0.2)
|
|
70
70
|
nokogiri (>= 1.5.9)
|
|
71
|
-
mail (2.
|
|
72
|
-
|
|
71
|
+
mail (2.7.0)
|
|
72
|
+
mini_mime (>= 0.1.1)
|
|
73
73
|
method_source (0.9.0)
|
|
74
|
-
|
|
75
|
-
mime-types-data (~> 3.2015)
|
|
76
|
-
mime-types-data (3.2016.0521)
|
|
74
|
+
mini_mime (1.0.0)
|
|
77
75
|
mini_portile2 (2.3.0)
|
|
78
76
|
minitest (5.10.3)
|
|
79
77
|
nio4r (2.1.0)
|
|
80
78
|
nokogiri (1.8.1)
|
|
81
79
|
mini_portile2 (~> 2.3.0)
|
|
82
80
|
rack (2.0.3)
|
|
83
|
-
rack-test (0.
|
|
81
|
+
rack-test (0.8.2)
|
|
84
82
|
rack (>= 1.0, < 3)
|
|
85
83
|
rails (5.1.4)
|
|
86
84
|
actioncable (= 5.1.4)
|
|
@@ -107,37 +105,33 @@ GEM
|
|
|
107
105
|
method_source
|
|
108
106
|
rake (>= 0.8.7)
|
|
109
107
|
thor (>= 0.18.1, < 2.0)
|
|
110
|
-
rake (12.
|
|
111
|
-
rspec (3.
|
|
112
|
-
rspec-core (~> 3.
|
|
113
|
-
rspec-expectations (~> 3.
|
|
114
|
-
rspec-mocks (~> 3.
|
|
115
|
-
rspec-core (3.
|
|
116
|
-
rspec-support (~> 3.
|
|
117
|
-
rspec-expectations (3.
|
|
108
|
+
rake (12.3.0)
|
|
109
|
+
rspec (3.7.0)
|
|
110
|
+
rspec-core (~> 3.7.0)
|
|
111
|
+
rspec-expectations (~> 3.7.0)
|
|
112
|
+
rspec-mocks (~> 3.7.0)
|
|
113
|
+
rspec-core (3.7.0)
|
|
114
|
+
rspec-support (~> 3.7.0)
|
|
115
|
+
rspec-expectations (3.7.0)
|
|
118
116
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
119
|
-
rspec-support (~> 3.
|
|
120
|
-
rspec-mocks (3.
|
|
117
|
+
rspec-support (~> 3.7.0)
|
|
118
|
+
rspec-mocks (3.7.0)
|
|
121
119
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
122
|
-
rspec-support (~> 3.
|
|
123
|
-
rspec-rails (3.
|
|
120
|
+
rspec-support (~> 3.7.0)
|
|
121
|
+
rspec-rails (3.7.2)
|
|
124
122
|
actionpack (>= 3.0)
|
|
125
123
|
activesupport (>= 3.0)
|
|
126
124
|
railties (>= 3.0)
|
|
127
|
-
rspec-core (~> 3.
|
|
128
|
-
rspec-expectations (~> 3.
|
|
129
|
-
rspec-mocks (~> 3.
|
|
130
|
-
rspec-support (~> 3.
|
|
131
|
-
rspec-support (3.
|
|
125
|
+
rspec-core (~> 3.7.0)
|
|
126
|
+
rspec-expectations (~> 3.7.0)
|
|
127
|
+
rspec-mocks (~> 3.7.0)
|
|
128
|
+
rspec-support (~> 3.7.0)
|
|
129
|
+
rspec-support (3.7.0)
|
|
132
130
|
simplecov (0.13.0)
|
|
133
131
|
docile (~> 1.1.0)
|
|
134
132
|
json (>= 1.8, < 3)
|
|
135
133
|
simplecov-html (~> 0.10.0)
|
|
136
134
|
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
135
|
sprockets (3.7.1)
|
|
142
136
|
concurrent-ruby (~> 1.0)
|
|
143
137
|
rack (> 1, < 3)
|
|
@@ -148,11 +142,11 @@ GEM
|
|
|
148
142
|
sqlite3 (1.3.13)
|
|
149
143
|
thor (0.20.0)
|
|
150
144
|
thread_safe (0.3.6)
|
|
151
|
-
tzinfo (1.2.
|
|
145
|
+
tzinfo (1.2.4)
|
|
152
146
|
thread_safe (~> 0.1)
|
|
153
147
|
websocket-driver (0.6.5)
|
|
154
148
|
websocket-extensions (>= 0.1.0)
|
|
155
|
-
websocket-extensions (0.1.
|
|
149
|
+
websocket-extensions (0.1.3)
|
|
156
150
|
|
|
157
151
|
PLATFORMS
|
|
158
152
|
ruby
|
|
@@ -168,7 +162,6 @@ DEPENDENCIES
|
|
|
168
162
|
rspec (~> 3.5)
|
|
169
163
|
rspec-rails (~> 3.5)
|
|
170
164
|
settingson!
|
|
171
|
-
spring-commands-rspec
|
|
172
165
|
sqlite3
|
|
173
166
|
|
|
174
167
|
BUNDLED WITH
|
data/lib/settingson.rb
CHANGED
data/lib/settingson/config.rb
CHANGED
data/lib/settingson/store.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
class Settingson::Store
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def initialize(klass:, path: nil
|
|
3
|
+
require 'settingson/store/default'
|
|
4
|
+
require 'settingson/store/general'
|
|
5
|
+
|
|
6
|
+
def initialize(klass:, path: nil)
|
|
7
7
|
@__klass = klass
|
|
8
8
|
@__path = path
|
|
9
|
-
@
|
|
9
|
+
@__config = klass.configure
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def to_s
|
|
@@ -35,8 +35,8 @@ class Settingson::Store
|
|
|
35
35
|
|
|
36
36
|
def method_missing(symbol, *args)
|
|
37
37
|
__debug
|
|
38
|
-
__debug("from\n\t#{caller[1..@
|
|
39
|
-
@
|
|
38
|
+
__debug("from\n\t#{caller[1..@__config.trace].join("\n\t")}") if
|
|
39
|
+
@__config.trace > 0
|
|
40
40
|
|
|
41
41
|
__references_action(symbol, *args) or __rescue_action(symbol.to_s, *args)
|
|
42
42
|
# __rescue_action(symbol.to_s, *args)
|
|
@@ -45,7 +45,7 @@ class Settingson::Store
|
|
|
45
45
|
protected
|
|
46
46
|
# TODO: move all methods to support class
|
|
47
47
|
def __debug(message="")
|
|
48
|
-
return unless @
|
|
48
|
+
return unless @__config.debug
|
|
49
49
|
message = sprintf("%s#%20s: %s",
|
|
50
50
|
self.class.name,
|
|
51
51
|
caller_locations.first.label,
|
|
@@ -58,7 +58,7 @@ class Settingson::Store
|
|
|
58
58
|
# return nil
|
|
59
59
|
# return nil unless ['model_name', 'to_model'].include?(symbol.to_s)
|
|
60
60
|
if @__klass and @__klass.respond_to?(symbol)
|
|
61
|
-
__debug("#{@__klass
|
|
61
|
+
__debug("#{@__klass} know what to do with #{symbol}")
|
|
62
62
|
@__klass.send(symbol, *args)
|
|
63
63
|
end
|
|
64
64
|
end
|
|
@@ -93,16 +93,17 @@ class Settingson::Store
|
|
|
93
93
|
else
|
|
94
94
|
@__klass.create!(key: @__path, value: value)
|
|
95
95
|
end
|
|
96
|
-
|
|
96
|
+
|
|
97
|
+
Rails.cache.write(__cache_key(@__path), value) if @__config.cache.enabled
|
|
97
98
|
value
|
|
98
99
|
end
|
|
99
100
|
|
|
100
101
|
def __get(key)
|
|
101
102
|
__update_search_path(key)
|
|
102
|
-
result =
|
|
103
|
+
result = __look_up_value(@__path)
|
|
103
104
|
|
|
104
105
|
if result.is_a?(ActiveRecord::RecordNotFound) or
|
|
105
|
-
result.is_a?(Settingson::Default
|
|
106
|
+
result.is_a?(Settingson::Store::Default)
|
|
106
107
|
__debug("return self with path: #{@__path}")
|
|
107
108
|
self
|
|
108
109
|
else
|
|
@@ -149,12 +150,16 @@ class Settingson::Store
|
|
|
149
150
|
key.try(:to_key).try(:join, '_') || key.id
|
|
150
151
|
end
|
|
151
152
|
|
|
153
|
+
def _search_path(key)
|
|
154
|
+
[@__path, key].compact.join('.')
|
|
155
|
+
end
|
|
156
|
+
|
|
152
157
|
def __update_search_path(key)
|
|
153
|
-
@__path =
|
|
158
|
+
@__path = _search_path(key)
|
|
154
159
|
end
|
|
155
160
|
|
|
156
|
-
def
|
|
157
|
-
result =
|
|
161
|
+
def __look_up_value(key)
|
|
162
|
+
result = @__config.cache.enabled ? __from_cache(key) : __from_db(key)
|
|
158
163
|
|
|
159
164
|
if result.is_a?(ActiveRecord::RecordNotFound)
|
|
160
165
|
__debug("looking in #{@__klass.name}.defaults[#{key}]")
|
|
@@ -165,22 +170,22 @@ class Settingson::Store
|
|
|
165
170
|
end
|
|
166
171
|
|
|
167
172
|
def __cache_key(key)
|
|
168
|
-
[ @
|
|
173
|
+
[ @__config.cache.namespace, key ].join('/')
|
|
169
174
|
end
|
|
170
175
|
|
|
171
|
-
def
|
|
176
|
+
def __from_cache(key)
|
|
172
177
|
__debug("looking in cache '#{__cache_key(key)}'")
|
|
173
178
|
Rails.cache.fetch(
|
|
174
179
|
__cache_key(key),
|
|
175
|
-
expires_in: @
|
|
176
|
-
race_condition_ttl: @
|
|
180
|
+
expires_in: @__config.cache.expires,
|
|
181
|
+
race_condition_ttl: @__config.cache.race_condition_ttl
|
|
177
182
|
) do
|
|
178
183
|
__debug("ask DB '#{key}'")
|
|
179
|
-
|
|
184
|
+
__from_db(key)
|
|
180
185
|
end
|
|
181
186
|
end
|
|
182
187
|
|
|
183
|
-
def
|
|
188
|
+
def __from_db(key)
|
|
184
189
|
@__klass.find_by!(key: key).value
|
|
185
190
|
rescue ActiveRecord::RecordNotFound
|
|
186
191
|
__debug("not found")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Settingson::Store::Default < Settingson::Store
|
|
2
|
+
|
|
3
|
+
@@__defaults = {}
|
|
4
|
+
|
|
5
|
+
def to_h
|
|
6
|
+
@@__defaults
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_ary
|
|
10
|
+
@@__defaults.to_a
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
protected
|
|
14
|
+
def __set(key, value)
|
|
15
|
+
@@__defaults[_search_path(key)] = value
|
|
16
|
+
@__path = nil
|
|
17
|
+
value
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def __get(key)
|
|
21
|
+
__update_search_path(key)
|
|
22
|
+
@@__defaults[@__path] || self
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
data/lib/settingson/version.rb
CHANGED
data/settingson.gemspec
CHANGED
|
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
|
|
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.5"
|
|
27
27
|
spec.add_development_dependency "rspec-rails", "~> 3.5"
|
|
28
28
|
spec.add_development_dependency "sqlite3"
|
|
29
|
-
spec.add_development_dependency "spring-commands-rspec"
|
|
30
29
|
spec.add_development_dependency "database_cleaner"
|
|
31
30
|
spec.add_development_dependency "faker"
|
|
32
31
|
# spec.add_development_dependency "rake"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Settingson::Default do
|
|
3
|
+
describe Settingson::Store::Default do
|
|
4
4
|
|
|
5
5
|
it 'not raises errors with empty block' do
|
|
6
6
|
expect{ Settings.defaults {} }.to_not raise_error
|
|
@@ -21,4 +21,16 @@ describe Settingson::Default do
|
|
|
21
21
|
expect( h['cached.key2'] ).to eq(word)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
describe '#to_h' do
|
|
25
|
+
it 'returns Hash' do
|
|
26
|
+
expect( Settings.defaults.to_h ).to be_a(Hash)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '#to_ary' do
|
|
31
|
+
it 'returns Array' do
|
|
32
|
+
expect( Settings.defaults.to_ary ).to be_a(Array)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
24
36
|
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.
|
|
4
|
+
version: 1.7.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- dan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -108,20 +108,6 @@ dependencies:
|
|
|
108
108
|
- - ">="
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
110
|
version: '0'
|
|
111
|
-
- !ruby/object:Gem::Dependency
|
|
112
|
-
name: spring-commands-rspec
|
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
|
114
|
-
requirements:
|
|
115
|
-
- - ">="
|
|
116
|
-
- !ruby/object:Gem::Version
|
|
117
|
-
version: '0'
|
|
118
|
-
type: :development
|
|
119
|
-
prerelease: false
|
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
-
requirements:
|
|
122
|
-
- - ">="
|
|
123
|
-
- !ruby/object:Gem::Version
|
|
124
|
-
version: '0'
|
|
125
111
|
- !ruby/object:Gem::Dependency
|
|
126
112
|
name: database_cleaner
|
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -180,9 +166,10 @@ files:
|
|
|
180
166
|
- lib/settingson.rb
|
|
181
167
|
- lib/settingson/config.rb
|
|
182
168
|
- lib/settingson/default.rb
|
|
183
|
-
- lib/settingson/default/store.rb
|
|
184
169
|
- lib/settingson/engine.rb
|
|
185
170
|
- lib/settingson/store.rb
|
|
171
|
+
- lib/settingson/store/default.rb
|
|
172
|
+
- lib/settingson/store/general.rb
|
|
186
173
|
- lib/settingson/utils.rb
|
|
187
174
|
- lib/settingson/version.rb
|
|
188
175
|
- settingson.gemspec
|
|
@@ -1,127 +0,0 @@
|
|
|
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
|