ez-settings 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/ez/settings/interface.rb +4 -4
- data/lib/ez/settings/interface/group.rb +1 -1
- data/lib/ez/settings/store.rb +19 -5
- 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: 66561fe692db0aab77ef9f297dc74afb7f14bc2d86d99c0b64799fc37623e7a4
|
4
|
+
data.tar.gz: 11799222bb160c1b7cdd19fe2dea75436cadb3feee340b0544d0b926183ed2b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 315ef0bcaa2828278dd3395747920a38da72a664108722847768ae38c2b7c761fdd0c50b1e0d1d9505fd4327597e58b4a97255ccbd4c55f7707514582af35694
|
7
|
+
data.tar.gz: e81791809179424aba13bbdc0bbabc7bf58d8e126f9d367a783a513af62f2263cbf6f611ef2cb2e76768fec4a429137d19d20054c88babd05335df3cad1062ae
|
data/README.md
CHANGED
@@ -59,7 +59,7 @@ app = Ez::Settings::Interface.define :app do # :app - interface name
|
|
59
59
|
end
|
60
60
|
|
61
61
|
# If you want to see all power of the engine, add this showcase:
|
62
|
-
group :showcase do
|
62
|
+
group :showcase, on_change: ->(changes) { YourHandler.call(changes) } do
|
63
63
|
key :string, default: -> { 'simple string' }
|
64
64
|
key :bool, type: :boolean, default: -> { true }
|
65
65
|
key :integer, type: :integer, default: -> { 777 }
|
@@ -67,6 +67,8 @@ app = Ez::Settings::Interface.define :app do # :app - interface name
|
|
67
67
|
key :not_validate, required: false, presence: false
|
68
68
|
key :not_for_ui, required: false, ui: false
|
69
69
|
end
|
70
|
+
# Group could have:
|
71
|
+
# :on_change - closure to call after the group is changed
|
70
72
|
# Keys could have:
|
71
73
|
# :type (string by default), now ez-settings supports only: string, boolean, integer and select
|
72
74
|
# :default value (as callable objects)
|
@@ -36,8 +36,8 @@ module Ez::Settings
|
|
36
36
|
self.instance_eval(&block)
|
37
37
|
end
|
38
38
|
|
39
|
-
def group(name, &block)
|
40
|
-
find_or_initialize_group(name, &block)
|
39
|
+
def group(name, options = {}, &block)
|
40
|
+
find_or_initialize_group(name, options, &block)
|
41
41
|
end
|
42
42
|
|
43
43
|
def keys
|
@@ -46,13 +46,13 @@ module Ez::Settings
|
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
-
def find_or_initialize_group(name, &block)
|
49
|
+
def find_or_initialize_group(name, options = {}, &block)
|
50
50
|
existing_group = groups.find { |g| g.name == name }
|
51
51
|
|
52
52
|
if existing_group
|
53
53
|
existing_group.instance_eval(&block)
|
54
54
|
else
|
55
|
-
add_group(Group.new(name, self.name, &block))
|
55
|
+
add_group(Group.new(name, self.name, options, &block))
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
data/lib/ez/settings/store.rb
CHANGED
@@ -6,12 +6,13 @@ module Ez::Settings
|
|
6
6
|
class Store
|
7
7
|
delegate :keys, to: :group
|
8
8
|
|
9
|
-
attr_reader :group, :errors, :backend
|
9
|
+
attr_reader :group, :errors, :backend, :on_change
|
10
10
|
|
11
|
-
def initialize(group, backend)
|
12
|
-
@group
|
13
|
-
@errors
|
14
|
-
@backend
|
11
|
+
def initialize(group, backend, options = {})
|
12
|
+
@group = group
|
13
|
+
@errors = ActiveModel::Errors.new(self)
|
14
|
+
@backend = backend
|
15
|
+
@on_change = options.fetch(:on_change, nil)
|
15
16
|
|
16
17
|
define_accessors
|
17
18
|
|
@@ -40,6 +41,8 @@ module Ez::Settings
|
|
40
41
|
validate
|
41
42
|
return self unless errors.empty?
|
42
43
|
|
44
|
+
on_change.call(changes(params)) if on_change
|
45
|
+
|
43
46
|
backend.write(schema)
|
44
47
|
|
45
48
|
self
|
@@ -76,5 +79,16 @@ module Ez::Settings
|
|
76
79
|
end
|
77
80
|
end
|
78
81
|
end
|
82
|
+
|
83
|
+
def changes(params)
|
84
|
+
new_data =
|
85
|
+
if params.is_a?(Hash)
|
86
|
+
params.symbolize_keys
|
87
|
+
elsif params.is_a?(ActionController::Parameters)
|
88
|
+
params.permit(keys.map(&:name)).to_h.symbolize_keys
|
89
|
+
end
|
90
|
+
|
91
|
+
new_data.reject { |k, v| data[k] == v }
|
92
|
+
end
|
79
93
|
end
|
80
94
|
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.2
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ez-core
|