ez-settings 0.2.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -17
- data/Rakefile +5 -3
- data/app/cells/ez/settings/base_cell.rb +41 -33
- data/app/cells/ez/settings/group/show.slim +1 -0
- data/app/cells/ez/settings/group_cell.rb +8 -6
- data/app/cells/ez/settings/index_cell.rb +2 -0
- data/app/cells/ez/settings/key_cell.rb +10 -8
- data/app/cells/ez/settings/nav_cell.rb +4 -2
- data/app/controllers/ez/settings/application_controller.rb +2 -0
- data/app/controllers/ez/settings/settings_controller.rb +2 -0
- data/app/helpers/ez/settings/application_helper.rb +2 -0
- data/app/models/ez/settings/active_record_store.rb +11 -0
- data/app/models/ez/settings/application_record.rb +2 -0
- data/config/routes.rb +2 -0
- data/lib/ez/settings.rb +2 -0
- data/lib/ez/settings/accessors.rb +2 -0
- data/lib/ez/settings/backend/active_record.rb +60 -0
- data/lib/ez/settings/backend/file_system.rb +2 -0
- data/lib/ez/settings/backend/redis.rb +9 -10
- data/lib/ez/settings/config.rb +2 -0
- data/lib/ez/settings/engine.rb +2 -0
- data/lib/ez/settings/interface.rb +6 -2
- data/lib/ez/settings/interface/group.rb +2 -0
- data/lib/ez/settings/interface/key.rb +4 -2
- data/lib/ez/settings/request_dispatcher.rb +3 -1
- data/lib/ez/settings/routes.rb +2 -0
- data/lib/ez/settings/store.rb +5 -3
- data/lib/ez/settings/version.rb +3 -1
- data/lib/generators/ez/settings/active_record_migrations_generator.rb +25 -0
- data/lib/generators/ez/settings/install_generator.rb +11 -6
- metadata +34 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0e61f349026e3e8e7f1d6c73f3dac27b1cf94759aaf0bd95804f3adc6ffb384
|
4
|
+
data.tar.gz: 3c8169673fabafc9c60da04029f33d9f5336b6607e4a3e7f82522aa9db56480f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b75bf279db5b2d01e2c0c3d349f8e8f431487934dbf379e381b1ff034e134bc9802979b33b3cf55e95bfc469782372762419f62afb9cfe16836243afde07ac07
|
7
|
+
data.tar.gz: d04873ffd18224f1ced6e1914fda9d0e836340e1b1d8e9672ac915494e89a6309297c3aa353fcaccf099fdc10d346710a2c2757857f1e2161ae047f796dc9251
|
data/README.md
CHANGED
@@ -9,10 +9,6 @@
|
|
9
9
|
- Convetion over configuration principles.
|
10
10
|
- Depends on [ez-core](https://github.com/ez-engines/ez-core)
|
11
11
|
|
12
|
-
If you are boring to read all this stuff maybe this video motivates you:
|
13
|
-
|
14
|
-
[YouTube demonstrates how easy we integrated ez-settings for our pivorak-web-app only by ±50 lines of code](https://www.youtube.com/watch?v=TiX0QDHEaKA&feature=youtu.be)
|
15
|
-
|
16
12
|
## Installation
|
17
13
|
Add this line to your application's Gemfile:
|
18
14
|
|
@@ -38,7 +34,7 @@ and `bundle install`
|
|
38
34
|
|
39
35
|
Generates initializer config file and I18n yaml file with english keys
|
40
36
|
|
41
|
-
`config/ez_settings.rb`
|
37
|
+
`config/initializers/ez_settings.rb`
|
42
38
|
```ruby
|
43
39
|
# By default engine try to inherit from ApplicationController, but you could change this:
|
44
40
|
# Ez::Settings.config.base_controller = 'Admin::BaseController'
|
@@ -82,11 +78,18 @@ end
|
|
82
78
|
# After defining settings interface groups/keys you need to configure it:
|
83
79
|
app.configure do |config|
|
84
80
|
# Backend adapter to store all settings
|
85
|
-
config.backend = Ez::Settings::Backend::
|
86
|
-
#
|
87
|
-
# config.
|
81
|
+
config.backend = Ez::Settings::Backend::ActiveRecord.new
|
82
|
+
# and DB table name that you can change as well
|
83
|
+
# config.active_record_table_name = :ez_settings_store
|
84
|
+
|
85
|
+
# YAML filesystem
|
86
|
+
# config.backend = Ez::Settings::Backend::FileSystem.new(Rails.root.join('config', 'settings.yml'))
|
88
87
|
|
89
|
-
#
|
88
|
+
# Redis
|
89
|
+
# require 'redis'
|
90
|
+
# config.backend = Ez::Settings::Backend::Redis.new(Redis.current, namespace: 'myapp')
|
91
|
+
|
92
|
+
# Default path for redirect in the settings controller
|
90
93
|
config.default_path = '/admin/settings'
|
91
94
|
|
92
95
|
# Pass your custom css classes through css_map config
|
@@ -139,6 +142,19 @@ Ez::Registry.in(:settings_interfaces, by: 'YourAppName') do |registry|
|
|
139
142
|
end
|
140
143
|
```
|
141
144
|
|
145
|
+
|
146
|
+
### Database storage as backend (ActiveRecord)
|
147
|
+
|
148
|
+
You can use migrations generator
|
149
|
+
|
150
|
+
`rails generate ez:settings:active_record_migrations`
|
151
|
+
|
152
|
+
Generates migration for `ez_settings_store` table.
|
153
|
+
|
154
|
+
`rails db:migrate`
|
155
|
+
|
156
|
+
|
157
|
+
|
142
158
|
### Routes
|
143
159
|
`config/routes.rb`
|
144
160
|
|
@@ -229,10 +245,13 @@ If you need, create locale file with this structure:
|
|
229
245
|
groups:
|
230
246
|
general:
|
231
247
|
label: General
|
248
|
+
description: General settings of your application
|
232
249
|
admin:
|
233
250
|
label: Admin
|
251
|
+
description: Admin area settings
|
234
252
|
showcase:
|
235
253
|
label: Showcase
|
254
|
+
description: Just an example of possible settings UI elements
|
236
255
|
keys:
|
237
256
|
string:
|
238
257
|
label: String
|
@@ -250,14 +269,16 @@ If you need, create locale file with this structure:
|
|
250
269
|
|
251
270
|
## TODO
|
252
271
|
This features will be implemented in upcoming 0.2 and 0.3 releases:
|
253
|
-
- JSON API endpoints and `ez_settings_api_for` routes helper
|
254
|
-
- Scoped settings (`:scope_id`, `:scope_type`)
|
255
|
-
-
|
256
|
-
- Interface description (and show at UI)
|
257
|
-
- Groups description (and show at UI)
|
258
|
-
- Keys description (and show at UI)
|
259
|
-
- Database storage as backend (ActiveRecord)
|
260
|
-
-
|
272
|
+
- [] JSON API endpoints and `ez_settings_api_for` routes helper
|
273
|
+
- [] Scoped settings (`:scope_id`, `:scope_type`)
|
274
|
+
- [] Controller before actions as configured callbacks (for external usage)
|
275
|
+
- [] Interface description (and show at UI)
|
276
|
+
- [] Groups description (and show at UI)
|
277
|
+
- [] Keys description (and show at UI)
|
278
|
+
- [] Database storage as backend (ActiveRecord)
|
279
|
+
- [] Backend#read method should receive app, group & key attributes and avoid loading all in case of SQL adapter
|
280
|
+
- [] UI frameworks adapters: bootsrap3, bootstrap4, foundation, semantic, etc.
|
281
|
+
- [X] Bug: Read only defaul values if ActiveRecord do not ready yet (migrations)
|
261
282
|
|
262
283
|
## Contributing
|
263
284
|
Fork => Fix => MR warmly welcomed!
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
4
|
require 'bundler/setup'
|
3
5
|
rescue LoadError
|
@@ -14,15 +16,15 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
16
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
17
|
end
|
16
18
|
|
17
|
-
APP_RAKEFILE = File.expand_path(
|
19
|
+
APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
|
18
20
|
load 'rails/tasks/engine.rake'
|
19
21
|
|
20
22
|
load 'rails/tasks/statistics.rake'
|
21
23
|
|
22
24
|
require 'bundler/gem_tasks'
|
23
25
|
|
24
|
-
require
|
26
|
+
require 'rspec/core/rake_task'
|
25
27
|
|
26
28
|
RSpec::Core::RakeTask.new(:spec)
|
27
29
|
|
28
|
-
task :
|
30
|
+
task default: :spec
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ez::Settings
|
2
4
|
class BaseCell < Cell::ViewModel
|
3
5
|
include RequestDispatcher
|
@@ -8,14 +10,15 @@ module Ez::Settings
|
|
8
10
|
delegate :params, :request, to: :controller
|
9
11
|
delegate :dynamic_css_map, to: :'interface.config'
|
10
12
|
|
11
|
-
SCOPE
|
12
|
-
LABEL
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
SCOPE = 'ez_settings'
|
14
|
+
LABEL = 'label'
|
15
|
+
DESCRIPTION = 'description'
|
16
|
+
INTERFACES = 'interfaces'
|
17
|
+
GROUPS = 'groups'
|
18
|
+
KEYS = 'keys'
|
19
|
+
ACTIONS = 'actions'
|
20
|
+
SAVE = 'save'
|
21
|
+
CANCEL = 'cancel'
|
19
22
|
|
20
23
|
def self.form
|
21
24
|
include ActionView::Helpers::FormHelper
|
@@ -43,27 +46,27 @@ module Ez::Settings
|
|
43
46
|
|
44
47
|
def css_map
|
45
48
|
{
|
46
|
-
nav_label:
|
47
|
-
nav_menu:
|
48
|
-
nav_menu_item:
|
49
|
-
overview_page_wrapper:
|
50
|
-
overview_page_section:
|
51
|
-
overview_page_section_header:
|
52
|
-
overview_page_section_content:
|
53
|
-
overview_page_section_content_key:
|
49
|
+
nav_label: 'ez-settings-nav-label',
|
50
|
+
nav_menu: 'ez-settings-nav-menu',
|
51
|
+
nav_menu_item: 'ez-settings-nav-menu-item',
|
52
|
+
overview_page_wrapper: 'ez-settings-overview',
|
53
|
+
overview_page_section: 'ez-settings-overview-section',
|
54
|
+
overview_page_section_header: 'ez-settings-overview-section-header',
|
55
|
+
overview_page_section_content: 'ez-settings-overview-section-content',
|
56
|
+
overview_page_section_content_key: 'ez-settings-overview-section-content-key',
|
54
57
|
overview_page_section_content_value: 'ez-settings-overview-section-content-value',
|
55
|
-
group_page_wrapper:
|
56
|
-
group_page_inner_wrapper:
|
57
|
-
group_page_header:
|
58
|
-
group_page_form_wrapper:
|
59
|
-
group_page_form_inner:
|
60
|
-
group_page_form_field_row:
|
61
|
-
group_page_form_string_wrapper:
|
62
|
-
group_page_form_boolean_wrapper:
|
63
|
-
group_page_form_select_wrapper:
|
64
|
-
group_page_actions_wrapper:
|
65
|
-
group_page_actions_save_button:
|
66
|
-
group_page_actions_cancel_link:
|
58
|
+
group_page_wrapper: 'ez-settings-group-wrapper',
|
59
|
+
group_page_inner_wrapper: 'ez-settings-group-inner-wrapper',
|
60
|
+
group_page_header: 'ez-settings-group-header',
|
61
|
+
group_page_form_wrapper: 'ez-settings-group-form-wrapper',
|
62
|
+
group_page_form_inner: 'ez-settings-group-form-inner',
|
63
|
+
group_page_form_field_row: 'ez-settings-group-form-field-row',
|
64
|
+
group_page_form_string_wrapper: 'ez-settings-group-form-string-wrapper',
|
65
|
+
group_page_form_boolean_wrapper: 'ez-settings-group-form-boolean-wrapper',
|
66
|
+
group_page_form_select_wrapper: 'ez-settings-group-form-select-wrapper',
|
67
|
+
group_page_actions_wrapper: 'ez-settings-group-actions-wrapper',
|
68
|
+
group_page_actions_save_button: 'ez-settings-group-actions-save-btn',
|
69
|
+
group_page_actions_cancel_link: 'ez-settings-group-actions-cancel-link'
|
67
70
|
}.merge(interface.config.custom_css_map)
|
68
71
|
end
|
69
72
|
|
@@ -71,10 +74,10 @@ module Ez::Settings
|
|
71
74
|
context[:controller]
|
72
75
|
end
|
73
76
|
|
74
|
-
def group_link(group,
|
77
|
+
def group_link(group, _options = {})
|
75
78
|
link_to i18n_group_label(group),
|
76
|
-
|
77
|
-
|
79
|
+
group_path(group),
|
80
|
+
class: css_for(:nav_menu_item, dynamic: "settings/#{group.name}")
|
78
81
|
end
|
79
82
|
|
80
83
|
def group_path(group)
|
@@ -82,12 +85,17 @@ module Ez::Settings
|
|
82
85
|
end
|
83
86
|
|
84
87
|
def i18n_group_label(group)
|
85
|
-
t(LABEL, scope:
|
88
|
+
t(LABEL, scope: [SCOPE, INTERFACES, group.interface, GROUPS, group.name],
|
86
89
|
default: group.name.to_s.humanize)
|
87
90
|
end
|
88
91
|
|
92
|
+
def i18n_group_description(group)
|
93
|
+
t(DESCRIPTION, scope: [SCOPE, INTERFACES, group.interface, GROUPS, group.name],
|
94
|
+
default: group.name.to_s.humanize)
|
95
|
+
end
|
96
|
+
|
89
97
|
def i18n_key_label(key)
|
90
|
-
t(LABEL, scope:
|
98
|
+
t(LABEL, scope: [SCOPE, INTERFACES, key.interface, GROUPS, key.group, KEYS, key.name],
|
91
99
|
default: key.name.to_s.humanize)
|
92
100
|
end
|
93
101
|
end
|
@@ -5,6 +5,7 @@
|
|
5
5
|
div class=(css_for :group_page_inner_wrapper)
|
6
6
|
div class=(css_for :group_page_header)
|
7
7
|
= i18n_group_label(group)
|
8
|
+
p = i18n_group_description(group)
|
8
9
|
|
9
10
|
div class=(css_for :group_page_form_wrapper)
|
10
11
|
= simple_form_for store, as: :settings, url: form_url, method: :put do |f|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ez::Settings
|
2
4
|
class GroupCell < BaseCell
|
3
5
|
form
|
@@ -11,16 +13,16 @@ module Ez::Settings
|
|
11
13
|
|
12
14
|
def save_button(form)
|
13
15
|
form.button :submit,
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
t(LABEL, scope: [SCOPE, INTERFACES, model.interface, ACTIONS, SAVE],
|
17
|
+
default: 'Save'),
|
18
|
+
class: css_for(:group_page_actions_save_button)
|
17
19
|
end
|
18
20
|
|
19
21
|
def cancel_link
|
20
|
-
link_to t(LABEL, scope:
|
22
|
+
link_to t(LABEL, scope: [SCOPE, INTERFACES, model.interface, ACTIONS, CANCEL],
|
21
23
|
default: 'Cancel'),
|
22
|
-
|
23
|
-
|
24
|
+
interface.config.default_path,
|
25
|
+
class: css_for(:group_page_actions_cancel_link)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ez::Settings
|
2
4
|
class KeyCell < BaseCell
|
3
5
|
form
|
@@ -8,15 +10,15 @@ module Ez::Settings
|
|
8
10
|
|
9
11
|
def html_options
|
10
12
|
{
|
11
|
-
label:
|
12
|
-
as:
|
13
|
-
collection:
|
14
|
-
include_blank:
|
15
|
-
required:
|
16
|
-
checked_value:
|
13
|
+
label: i18n_key_label(model),
|
14
|
+
as: model.type,
|
15
|
+
collection: model.collection,
|
16
|
+
include_blank: model.default.present?,
|
17
|
+
required: model.required?,
|
18
|
+
checked_value: true.to_s,
|
17
19
|
unchecked_value: false.to_s,
|
18
|
-
wrapper:
|
19
|
-
right_label:
|
20
|
+
wrapper: model.wrapper,
|
21
|
+
right_label: model.suffix,
|
20
22
|
input_html: {
|
21
23
|
min: model.min
|
22
24
|
}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ez::Settings
|
2
4
|
class NavCell < BaseCell
|
3
5
|
def nav_label
|
@@ -6,8 +8,8 @@ module Ez::Settings
|
|
6
8
|
|
7
9
|
def settings_link
|
8
10
|
link_to nav_label,
|
9
|
-
|
10
|
-
|
11
|
+
interface.config.default_path,
|
12
|
+
class: css_for(:nav_menu_item, dynamic: 'settings/')
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ez
|
4
|
+
module Settings
|
5
|
+
class ActiveRecordStore < Ez::Settings::ApplicationRecord
|
6
|
+
self.table_name = Ez::Settings.config.active_record_table_name || :ez_settings
|
7
|
+
|
8
|
+
validates :key, uniqueness: { scope: :group }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/config/routes.rb
CHANGED
data/lib/ez/settings.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
module Ez::Settings
|
6
|
+
module Backend
|
7
|
+
class ActiveRecord
|
8
|
+
def read
|
9
|
+
return {} unless try_db_connection && check_settings_table
|
10
|
+
|
11
|
+
ActiveRecordStore.all.each_with_object({}) do |settings, hsh|
|
12
|
+
hsh[settings.group] ||= {}
|
13
|
+
hsh[settings.group][settings.key] = settings.value
|
14
|
+
end.deep_symbolize_keys
|
15
|
+
end
|
16
|
+
|
17
|
+
def write(data)
|
18
|
+
return unless try_db_connection && check_settings_table
|
19
|
+
|
20
|
+
group = data.keys[0]
|
21
|
+
pairs = data.values[0]
|
22
|
+
existing_settings = ActiveRecordStore.where(group: group, key: pairs.keys)
|
23
|
+
pairs.map do |key, value|
|
24
|
+
record(existing_settings, key, value) || ActiveRecordStore.new(group: group, key: key, value: value)
|
25
|
+
end.each(&:save!)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def record(existing_settings, key, value)
|
31
|
+
record = existing_settings.find { |r| r.key == key.to_s }
|
32
|
+
|
33
|
+
return unless record
|
34
|
+
|
35
|
+
record.tap { |r| r.value = value }
|
36
|
+
end
|
37
|
+
|
38
|
+
def try_db_connection
|
39
|
+
::ActiveRecord::Base.connection
|
40
|
+
rescue ::ActiveRecord::NoDatabaseError
|
41
|
+
message('Database does not exist')
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_settings_table
|
46
|
+
settings_table = Ez::Settings.config.active_record_table_name || :ez_settings
|
47
|
+
if ::ActiveRecord::Base.connection.data_source_exists?(settings_table)
|
48
|
+
return true
|
49
|
+
end
|
50
|
+
|
51
|
+
message("Table #{settings_table} does not exists. Please, check migrations")
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
def message(txt, level = 'WARN')
|
56
|
+
STDOUT.puts("[#{level}] Ez::Settings: #{txt}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,37 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
|
-
require 'redis'
|
3
4
|
require 'active_support/hash_with_indifferent_access'
|
4
5
|
|
5
6
|
module Ez::Settings
|
6
7
|
module Backend
|
7
8
|
class Redis
|
8
9
|
PREFIX = 'ez:settings'
|
10
|
+
NAMESPACE = 'config'
|
11
|
+
|
12
|
+
attr_reader :connection, :namespace
|
9
13
|
|
10
|
-
def initialize(namespace)
|
14
|
+
def initialize(connection, namespace: NAMESPACE)
|
15
|
+
@connection = connection
|
11
16
|
@namespace = namespace
|
12
17
|
end
|
13
18
|
|
14
19
|
def read
|
15
|
-
value =
|
20
|
+
value = connection.get(key)
|
16
21
|
value.nil? ? {} : JSON.parse(value).deep_symbolize_keys
|
17
22
|
end
|
18
23
|
|
19
24
|
def write(data)
|
20
25
|
new_data = read.merge(data)
|
21
|
-
|
26
|
+
connection.set(key, JSON.generate(new_data))
|
22
27
|
end
|
23
28
|
|
24
29
|
private
|
25
30
|
|
26
|
-
attr_reader :namespace
|
27
|
-
|
28
31
|
def key
|
29
32
|
@key ||= "#{PREFIX}:#{namespace}"
|
30
33
|
end
|
31
|
-
|
32
|
-
def client
|
33
|
-
@client ||= ::Redis.current
|
34
|
-
end
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
data/lib/ez/settings/config.rb
CHANGED
data/lib/ez/settings/engine.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'interface/group'
|
2
4
|
require_relative 'interface/key'
|
3
5
|
require_relative 'store'
|
4
6
|
|
5
7
|
require 'ez/configurator'
|
6
8
|
require 'ez/settings/backend/file_system'
|
9
|
+
require 'ez/settings/backend/active_record'
|
7
10
|
|
8
11
|
module Ez::Settings
|
9
12
|
class Interface
|
@@ -29,11 +32,12 @@ module Ez::Settings
|
|
29
32
|
|
30
33
|
def initialize(name)
|
31
34
|
@name = name
|
32
|
-
@keys
|
35
|
+
@keys = []
|
36
|
+
@groups = []
|
33
37
|
end
|
34
38
|
|
35
39
|
def define(&block)
|
36
|
-
|
40
|
+
instance_eval(&block)
|
37
41
|
end
|
38
42
|
|
39
43
|
def group(name, options = {}, &block)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ez::Settings
|
2
4
|
class Interface
|
3
5
|
class Key
|
@@ -21,8 +23,8 @@ module Ez::Settings
|
|
21
23
|
end
|
22
24
|
|
23
25
|
# Alias all boolean-like options to predicates methods, please
|
24
|
-
|
25
|
-
|
26
|
+
alias ui? ui
|
27
|
+
alias required? required
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ez
|
2
4
|
module Settings
|
3
5
|
module RequestDispatcher
|
@@ -8,7 +10,7 @@ module Ez
|
|
8
10
|
|
9
11
|
# TODO: add raise exception in nil
|
10
12
|
Ez::Registry.data(:settings_interfaces).find do |interface|
|
11
|
-
interface.name ==
|
13
|
+
interface.name == params[:ez_settings_interface].to_sym
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
data/lib/ez/settings/routes.rb
CHANGED
data/lib/ez/settings/store.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_model'
|
2
4
|
|
3
5
|
require 'ez/settings/config'
|
@@ -23,7 +25,7 @@ module Ez::Settings
|
|
23
25
|
@errors = ActiveModel::Errors.new(self)
|
24
26
|
|
25
27
|
group.keys.select(&:required?).each do |key|
|
26
|
-
errors.add(key.name, "can't be blank") if
|
28
|
+
errors.add(key.name, "can't be blank") if send(key.name).blank?
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -36,12 +38,12 @@ module Ez::Settings
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def update(params)
|
39
|
-
params.each { |key, value|
|
41
|
+
params.each { |key, value| public_send("#{key}=", value) }
|
40
42
|
|
41
43
|
validate
|
42
44
|
return self unless errors.empty?
|
43
45
|
|
44
|
-
on_change
|
46
|
+
on_change&.call(changes(params))
|
45
47
|
|
46
48
|
backend.write(schema)
|
47
49
|
|
data/lib/ez/settings/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ez::Settings
|
4
|
+
class ActiveRecordMigrationsGenerator < Rails::Generators::Base
|
5
|
+
def create_migration
|
6
|
+
create_file "db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S')}_create_ez_settings.rb",
|
7
|
+
"class CreateEzSettings < ActiveRecord::Migration[5.0]
|
8
|
+
def change
|
9
|
+
create_table :ez_settings do |t|
|
10
|
+
t.string :group, null: false
|
11
|
+
t.string :key, null: false
|
12
|
+
t.string :value, null: false
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
|
17
|
+
add_index :ez_settings, :key
|
18
|
+
add_index :ez_settings, :group
|
19
|
+
add_index :ez_settings, [:key, :group], unique: true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ez::Settings
|
2
4
|
class InstallGenerator < Rails::Generators::Base
|
3
5
|
def create_initializer_file
|
4
|
-
create_file
|
5
|
-
|
6
|
+
create_file 'config/initializers/ez_settings.rb',
|
7
|
+
"# By default engine try to inherit from ApplicationController, but you could change this:
|
6
8
|
# Ez::Settings.config.base_controller = 'Admin::BaseController'
|
7
9
|
#
|
8
10
|
# Then you should define settings interfaces (you can create as much as you need)
|
@@ -94,8 +96,8 @@ end"
|
|
94
96
|
end
|
95
97
|
|
96
98
|
def create_locale_file
|
97
|
-
create_file
|
98
|
-
|
99
|
+
create_file 'config/locales/ez_settings.en.yml',
|
100
|
+
"en:
|
99
101
|
ez_settings:
|
100
102
|
label: Ez Settings
|
101
103
|
interfaces:
|
@@ -103,16 +105,19 @@ end"
|
|
103
105
|
label: App Settings
|
104
106
|
actions:
|
105
107
|
save:
|
106
|
-
label:
|
108
|
+
label: Update
|
107
109
|
cancel:
|
108
|
-
label: Cancel
|
110
|
+
label: Cancel
|
109
111
|
groups:
|
110
112
|
general:
|
111
113
|
label: General
|
114
|
+
description: General settings of your application
|
112
115
|
admin:
|
113
116
|
label: Admin
|
117
|
+
description: Admin area settings
|
114
118
|
showcase:
|
115
119
|
label: Showcase
|
120
|
+
description: Just an example of possible settings UI elements
|
116
121
|
keys:
|
117
122
|
string:
|
118
123
|
label: String
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volodya Sveredyuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ez-core
|
@@ -16,86 +16,78 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rails
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 5.0.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 5.0.0
|
26
|
+
version: 0.2.0
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: cells-rails
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.0
|
33
|
+
version: 0.1.0
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.0
|
40
|
+
version: 0.1.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: cells-slim
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.0.
|
47
|
+
version: 0.0.6
|
62
48
|
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.0.
|
54
|
+
version: 0.0.6
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: rails
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - "
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.0.0
|
62
|
+
- - "<="
|
74
63
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
64
|
+
version: 7.0.0
|
76
65
|
type: :runtime
|
77
66
|
prerelease: false
|
78
67
|
version_requirements: !ruby/object:Gem::Requirement
|
79
68
|
requirements:
|
80
|
-
- - "
|
69
|
+
- - ">="
|
81
70
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
71
|
+
version: 5.0.0
|
72
|
+
- - "<="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 7.0.0
|
83
75
|
- !ruby/object:Gem::Dependency
|
84
76
|
name: simple_form
|
85
77
|
requirement: !ruby/object:Gem::Requirement
|
86
78
|
requirements:
|
87
79
|
- - ">="
|
88
80
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
81
|
+
version: 5.0.1
|
90
82
|
type: :runtime
|
91
83
|
prerelease: false
|
92
84
|
version_requirements: !ruby/object:Gem::Requirement
|
93
85
|
requirements:
|
94
86
|
- - ">="
|
95
87
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
88
|
+
version: 5.0.1
|
97
89
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
90
|
+
name: capybara
|
99
91
|
requirement: !ruby/object:Gem::Requirement
|
100
92
|
requirements:
|
101
93
|
- - ">="
|
@@ -109,7 +101,7 @@ dependencies:
|
|
109
101
|
- !ruby/object:Gem::Version
|
110
102
|
version: '0'
|
111
103
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
104
|
+
name: faker
|
113
105
|
requirement: !ruby/object:Gem::Requirement
|
114
106
|
requirements:
|
115
107
|
- - ">="
|
@@ -123,7 +115,7 @@ dependencies:
|
|
123
115
|
- !ruby/object:Gem::Version
|
124
116
|
version: '0'
|
125
117
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
118
|
+
name: fakeredis
|
127
119
|
requirement: !ruby/object:Gem::Requirement
|
128
120
|
requirements:
|
129
121
|
- - ">="
|
@@ -137,7 +129,7 @@ dependencies:
|
|
137
129
|
- !ruby/object:Gem::Version
|
138
130
|
version: '0'
|
139
131
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
132
|
+
name: generator_spec
|
141
133
|
requirement: !ruby/object:Gem::Requirement
|
142
134
|
requirements:
|
143
135
|
- - ">="
|
@@ -151,7 +143,7 @@ dependencies:
|
|
151
143
|
- !ruby/object:Gem::Version
|
152
144
|
version: '0'
|
153
145
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
146
|
+
name: guard-rspec
|
155
147
|
requirement: !ruby/object:Gem::Requirement
|
156
148
|
requirements:
|
157
149
|
- - ">="
|
@@ -179,7 +171,7 @@ dependencies:
|
|
179
171
|
- !ruby/object:Gem::Version
|
180
172
|
version: '0'
|
181
173
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
174
|
+
name: pry-rails
|
183
175
|
requirement: !ruby/object:Gem::Requirement
|
184
176
|
requirements:
|
185
177
|
- - ">="
|
@@ -193,7 +185,7 @@ dependencies:
|
|
193
185
|
- !ruby/object:Gem::Version
|
194
186
|
version: '0'
|
195
187
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
188
|
+
name: rspec-rails
|
197
189
|
requirement: !ruby/object:Gem::Requirement
|
198
190
|
requirements:
|
199
191
|
- - ">="
|
@@ -207,7 +199,7 @@ dependencies:
|
|
207
199
|
- !ruby/object:Gem::Version
|
208
200
|
version: '0'
|
209
201
|
- !ruby/object:Gem::Dependency
|
210
|
-
name:
|
202
|
+
name: simplecov
|
211
203
|
requirement: !ruby/object:Gem::Requirement
|
212
204
|
requirements:
|
213
205
|
- - ">="
|
@@ -221,7 +213,7 @@ dependencies:
|
|
221
213
|
- !ruby/object:Gem::Version
|
222
214
|
version: '0'
|
223
215
|
- !ruby/object:Gem::Dependency
|
224
|
-
name:
|
216
|
+
name: sqlite3
|
225
217
|
requirement: !ruby/object:Gem::Requirement
|
226
218
|
requirements:
|
227
219
|
- - ">="
|
@@ -259,10 +251,12 @@ files:
|
|
259
251
|
- app/controllers/ez/settings/application_controller.rb
|
260
252
|
- app/controllers/ez/settings/settings_controller.rb
|
261
253
|
- app/helpers/ez/settings/application_helper.rb
|
254
|
+
- app/models/ez/settings/active_record_store.rb
|
262
255
|
- app/models/ez/settings/application_record.rb
|
263
256
|
- config/routes.rb
|
264
257
|
- lib/ez/settings.rb
|
265
258
|
- lib/ez/settings/accessors.rb
|
259
|
+
- lib/ez/settings/backend/active_record.rb
|
266
260
|
- lib/ez/settings/backend/file_system.rb
|
267
261
|
- lib/ez/settings/backend/redis.rb
|
268
262
|
- lib/ez/settings/config.rb
|
@@ -274,6 +268,7 @@ files:
|
|
274
268
|
- lib/ez/settings/routes.rb
|
275
269
|
- lib/ez/settings/store.rb
|
276
270
|
- lib/ez/settings/version.rb
|
271
|
+
- lib/generators/ez/settings/active_record_migrations_generator.rb
|
277
272
|
- lib/generators/ez/settings/install_generator.rb
|
278
273
|
homepage: https://github.com/ez-engines
|
279
274
|
licenses:
|
@@ -294,8 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
294
289
|
- !ruby/object:Gem::Version
|
295
290
|
version: '0'
|
296
291
|
requirements: []
|
297
|
-
|
298
|
-
rubygems_version: 2.7.6
|
292
|
+
rubygems_version: 3.0.6
|
299
293
|
signing_key:
|
300
294
|
specification_version: 4
|
301
295
|
summary: Easy settings engine for Rails app.
|