custom_rails_settings_cached 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c90d324da6f1105a3787d6fe5e425cde77e7ef22b76f93f72029cb6b6f5775f
4
- data.tar.gz: 4926f1c2a6850691bb3770f6463905f0c687cf333b0db39d008a11b54b06a86d
3
+ metadata.gz: 29d27addc040a72886822abd305924de2c6be632e6a0bf9ec2b5b74c72877fa0
4
+ data.tar.gz: bfccea2e5065766bb4d81f416ef541bb0c967fd733334b619388c3f25881171a
5
5
  SHA512:
6
- metadata.gz: b33a6abb15314f0d997e36e6daff2cdf9c26586afc3cd2275cef5ac84e2df70e0d199d32473c3b42f2f951a2b7e7a7730c76b8c86f519224655679ed5574f74d
7
- data.tar.gz: 6c331873e2b23396493ce97de3abe4532559a6e3b3901cbf71de5751ba5a7a67319ec7e10d93cc5def42e7c9b96eac6135189e7677c25af8d24abd82a2b0ed4e
6
+ metadata.gz: 423381285f2ebb21f98f1740821ab058a2f062b44132fc5426493607bef6bd496401b166eb0d554f29e67ee441c757908a2b6aead1a33d384ed54d88143a93f9
7
+ data.tar.gz: ff535dee29861d258bd2ed365647958d7e9f2d77c4ae6ef8de7f6fa2f6fffc83e3e4926389461d40a3faa6bad70451b829474ea1975a2cdd66d0b226b90c6138
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- custom_rails_settings_cached (0.1.0)
4
+ custom_rails_settings_cached (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,12 +1,13 @@
1
1
  # CustomRailsSettingsCached
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/custom_rails_settings_cached`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- Add this line to your application's Gemfile:
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
- TODO: Write usage instructions here
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
- if self::CUSTOM_RAILS_SETTINGS_KEYS.is_a?(Array)
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
- self::CUSTOM_RAILS_SETTINGS_KEYS.each do |setting_key|
59
- self.define_method "#{setting_key}" do
60
- self.get_settings setting_key
61
- end
62
- self.define_method "#{setting_key}=" do |setting_value|
63
- self.init_setting(setting_key, setting_value)
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 self::CUSTOM_RAILS_SETTINGS_KEYS.is_a?(Hash)
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
- self::CUSTOM_RAILS_SETTINGS_KEYS.each do |k, v|
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
- else
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CustomRailsSettingsCached
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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.0
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-21 00:00:00.000000000 Z
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: