custom_rails_settings_cached 0.1.0 → 0.1.1
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/Gemfile.lock +1 -1
- data/README.md +68 -5
- data/lib/custom_rails_settings_cached.rb +20 -10
- data/lib/custom_rails_settings_cached/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: 29d27addc040a72886822abd305924de2c6be632e6a0bf9ec2b5b74c72877fa0
|
|
4
|
+
data.tar.gz: bfccea2e5065766bb4d81f416ef541bb0c967fd733334b619388c3f25881171a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 423381285f2ebb21f98f1740821ab058a2f062b44132fc5426493607bef6bd496401b166eb0d554f29e67ee441c757908a2b6aead1a33d384ed54d88143a93f9
|
|
7
|
+
data.tar.gz: ff535dee29861d258bd2ed365647958d7e9f2d77c4ae6ef8de7f6fa2f6fffc83e3e4926389461d40a3faa6bad70451b829474ea1975a2cdd66d0b226b90c6138
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# CustomRailsSettingsCached
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
|
3
|
+
My Custom with Rails Settings Cached. Easy to setup and use.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
You need install [Rails Settings Cached](https://github.com/huacnlee/rails-settings-cached) to use this gem.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Then, ddd this line to your application's Gemfile:
|
|
10
11
|
|
|
11
12
|
```ruby
|
|
12
13
|
gem 'custom_rails_settings_cached'
|
|
@@ -22,7 +23,69 @@ Or install it yourself as:
|
|
|
22
23
|
|
|
23
24
|
## Usage
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
Must define `CUSTOM_RAILS_SETTINGS_KEYS` before `include CustomRailsSettingsCached`
|
|
27
|
+
|
|
28
|
+
*CUSTOM_RAILS_SETTINGS_KEYS* can be Array or Hash.
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
CUSTOM_RAILS_SETTINGS_KEYS = {
|
|
32
|
+
google_analytics: [:enabled, :tracking_code],
|
|
33
|
+
facebook_pixel_ads: [:enabled, :tracking_code]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# Or
|
|
37
|
+
|
|
38
|
+
CUSTOM_RAILS_SETTINGS_KEYS = [:google_analytics, :facebook_pixel_ads]
|
|
39
|
+
|
|
40
|
+
# Or
|
|
41
|
+
|
|
42
|
+
CUSTOM_RAILS_SETTINGS_KEYS = {
|
|
43
|
+
google_analytics: :tracking_code,
|
|
44
|
+
facebook_pixel_ads: [:enabled, :tracking_code]
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
Then, include `CustomRailsSettingsCached` in your model.
|
|
48
|
+
Exam:
|
|
49
|
+
```ruby
|
|
50
|
+
include CustomRailsSettingsCached
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or, can use with your custom concern.
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
require 'custom_rails_settings_cached'
|
|
57
|
+
|
|
58
|
+
module MyCustomRailsSetting
|
|
59
|
+
def self.included klass
|
|
60
|
+
klass.include CustomRailsSettingsCached
|
|
61
|
+
|
|
62
|
+
# custom more here
|
|
63
|
+
# klass.class_eval do
|
|
64
|
+
# has_many :players
|
|
65
|
+
# validates :number_of_player, presence: true
|
|
66
|
+
# end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
Then use `include MyCustomRailsSetting` at model.
|
|
72
|
+
|
|
73
|
+
Exams:
|
|
74
|
+
|
|
75
|
+
**Get Value**
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
object = YourModel.first
|
|
79
|
+
object.google_analytics_tracking_code
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Set Value**
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
object = YourModel.first
|
|
86
|
+
object.update google_analytics_tracking_code: '123456ABCDEF'
|
|
87
|
+
```
|
|
88
|
+
|
|
26
89
|
|
|
27
90
|
## Development
|
|
28
91
|
|
|
@@ -52,24 +52,34 @@ module CustomRailsSettingsCached
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
if defined?(self::CUSTOM_RAILS_SETTINGS_KEYS)
|
|
55
|
-
|
|
55
|
+
build_custom_settings_methods self::CUSTOM_RAILS_SETTINGS_KEYS
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
module ClassMethods
|
|
60
|
+
def build_custom_settings_methods(custom_settings)
|
|
61
|
+
if custom_settings.is_a?(Array)
|
|
56
62
|
# Exam:
|
|
57
63
|
# CUSTOM_RAILS_SETTINGS_KEYS = [:google_analytics, :facebook_pixel_ads]
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
self.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
self.
|
|
64
|
+
custom_settings.each do |setting_key|
|
|
65
|
+
if setting_key.is_a?(Symbol)
|
|
66
|
+
self.define_method "#{setting_key}" do
|
|
67
|
+
self.get_settings setting_key
|
|
68
|
+
end
|
|
69
|
+
self.define_method "#{setting_key}=" do |setting_value|
|
|
70
|
+
self.init_setting(setting_key, setting_value)
|
|
71
|
+
end
|
|
72
|
+
else
|
|
73
|
+
self.build_custom_settings_methods setting_key
|
|
64
74
|
end
|
|
65
75
|
end
|
|
66
|
-
elsif
|
|
76
|
+
elsif custom_settings.is_a?(Hash)
|
|
67
77
|
# Exam:
|
|
68
78
|
# CUSTOM_RAILS_SETTINGS_KEYS = {
|
|
69
79
|
# google_analytics: [:enabled, :tracking_code],
|
|
70
80
|
# facebook_pixel_ads: [:enabled, :tracking_code]
|
|
71
81
|
# }
|
|
72
|
-
|
|
82
|
+
custom_settings.each do |k, v|
|
|
73
83
|
if v.is_a?(Array)
|
|
74
84
|
v.each do |setting_key|
|
|
75
85
|
# Use: Partner.first.google_analytics_enabled
|
|
@@ -82,7 +92,7 @@ module CustomRailsSettingsCached
|
|
|
82
92
|
self.init_setting(store_setting_key, setting_value)
|
|
83
93
|
end
|
|
84
94
|
end
|
|
85
|
-
|
|
95
|
+
elsif v.is_a?(Symbol)
|
|
86
96
|
# Use: Partner.first.google_analytics
|
|
87
97
|
self.define_method "#{v}" do
|
|
88
98
|
self.get_settings v
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: custom_rails_settings_cached
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Derek Nguyen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-03-
|
|
11
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: My custom with Rails Settings Cached
|
|
14
14
|
email:
|