ez-settings 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -5
- data/lib/ez/settings/accessors.rb +51 -17
- data/lib/ez/settings/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f55bd8dda018755a4db33fd94e9232669074afdc7af2029de8e5728e92ff80a
|
4
|
+
data.tar.gz: c0f36d36db6adeae4880bdb7ef4598c1c9ba4bbaadb1f8bd9ca52c0e27d868f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a50de648b5c2d1ce8ef1773f9fee0f9967352ef91775d76535fc2e652b358110d90c0fa6d9e2f802df5f17d09c4b4fbd0ad35af785926b26cb31a47d2358d3f
|
7
|
+
data.tar.gz: 73a21c257b75f87b41708795dc57a1b2167d4c3f37412448afa79d4b5d55933ba0438a6f200d4cce1d003376d05b8ae4490e25f7b734283be42355cedbc1b425
|
data/README.md
CHANGED
@@ -175,13 +175,25 @@ GET/PUT: /admin/settings/showcase - showcase group settings
|
|
175
175
|
```
|
176
176
|
|
177
177
|
### Settings accessors
|
178
|
-
|
178
|
+
To access your settings use template `Ez::Settings['interface', 'group', 'key']`.
|
179
|
+
|
180
|
+
Access interface:
|
181
|
+
```ruby
|
182
|
+
Ez::Settings[:app]
|
183
|
+
#=> <Ez::Settings::Interface:0x007ff1ea7d3168 @groups=[...], @keys=[], @name=:app>
|
184
|
+
```
|
185
|
+
|
186
|
+
Access group:
|
179
187
|
```ruby
|
180
|
-
Ez::Settings[:
|
181
|
-
Ez::Settings
|
182
|
-
|
188
|
+
Ez::Settings[:app, :general]
|
189
|
+
#=> <Ez::Settings::Interface::Group:0x007ff1ea7d2f88 @interface=:app, @keys=[...], @name=:general, @options={}>
|
190
|
+
```
|
191
|
+
|
192
|
+
Access setting value:
|
193
|
+
```ruby
|
194
|
+
Ez::Settings[:app, :general, :app_title]
|
195
|
+
# => 'Main app title'
|
183
196
|
```
|
184
|
-
Just use template: `Ez::Settings['interface', 'group', 'key']`
|
185
197
|
|
186
198
|
In the case of missing interface/group/key you will receive one of exceptions:
|
187
199
|
```
|
@@ -189,6 +201,7 @@ NotRegistredInterfaceError
|
|
189
201
|
NotRegistredGroupError
|
190
202
|
NotRegistredKeyError
|
191
203
|
```
|
204
|
+
|
192
205
|
Be careful ;)
|
193
206
|
|
194
207
|
### I18n
|
@@ -4,28 +4,62 @@ module Ez::Settings
|
|
4
4
|
NotRegistredKeyError = Class.new(StandardError)
|
5
5
|
|
6
6
|
module Accessors
|
7
|
-
def [](interface_name, group_name, key_name)
|
8
|
-
interface =
|
9
|
-
interface.name == interface_name.to_sym
|
10
|
-
end
|
11
|
-
|
12
|
-
unless interface
|
13
|
-
raise NotRegistredInterfaceError, "Interface #{interface_name} is not registred!"
|
14
|
-
end
|
7
|
+
def [](interface_name, group_name = nil, key_name = nil)
|
8
|
+
interface = interface(interface_name)
|
15
9
|
|
16
|
-
|
10
|
+
not_registered_interface!(interface_name) unless interface
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
if only_interface?(interface, group_name, key_name)
|
13
|
+
interface
|
14
|
+
else
|
15
|
+
group = group(interface, group_name)
|
21
16
|
|
22
|
-
|
17
|
+
not_registered_group!(interface_name, group_name) unless group
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
if interface_and_group?(interface, group_name, key_name)
|
20
|
+
group(interface, group_name)
|
21
|
+
else
|
22
|
+
begin
|
23
|
+
store(interface, group).send(key_name.to_sym)
|
24
|
+
rescue NoMethodError
|
25
|
+
not_registered_key!(interface_name, group_name, key_name)
|
26
|
+
end
|
27
|
+
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
private_class_method def self.interface(interface_name)
|
33
|
+
Ez::Registry.data(:settings_interfaces).find do |interface|
|
34
|
+
interface.name == interface_name.to_sym
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private_class_method def self.group(interface, group_name)
|
39
|
+
interface.groups.find { |g| g.name == group_name.to_sym }
|
40
|
+
end
|
41
|
+
|
42
|
+
private_class_method def self.store(interface, group)
|
43
|
+
Ez::Settings::Store.new(group, interface.config.backend)
|
44
|
+
end
|
45
|
+
|
46
|
+
private_class_method def self.only_interface?(interface, group_name, key_name)
|
47
|
+
interface && group_name.nil? && key_name.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
private_class_method def self.interface_and_group?(interface, group_name, key_name)
|
51
|
+
interface && group_name && key_name.nil?
|
52
|
+
end
|
53
|
+
|
54
|
+
private_class_method def self.not_registered_interface!(interface_name)
|
55
|
+
raise NotRegistredInterfaceError, "Interface #{interface_name} is not registred!"
|
56
|
+
end
|
57
|
+
|
58
|
+
private_class_method def self.not_registered_group!(interface_name, group_name)
|
59
|
+
raise NotRegistredGroupError, "Group #{group_name} is not registred for #{interface_name} interface"
|
60
|
+
end
|
61
|
+
|
62
|
+
private_class_method def self.not_registered_key!(interface_name, group_name, key_name)
|
63
|
+
raise NotRegistredKeyError, "Key #{key_name} is not registred for #{interface_name} interface, #{group_name} group"
|
64
|
+
end
|
31
65
|
end
|
data/lib/ez/settings/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ez-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volodya Sveredyuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ez-core
|