custom_rails_settings_cached 0.1.1 → 0.1.2

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: 29d27addc040a72886822abd305924de2c6be632e6a0bf9ec2b5b74c72877fa0
4
- data.tar.gz: bfccea2e5065766bb4d81f416ef541bb0c967fd733334b619388c3f25881171a
3
+ metadata.gz: 17327ed70c7e7ba8ddad8ee0d098985f678dc0b46932531f3d87d4e0bcd10dae
4
+ data.tar.gz: 93d282446db83f79f3290f493545affa6daf5e4189c74db23c8221c65940d7c9
5
5
  SHA512:
6
- metadata.gz: 423381285f2ebb21f98f1740821ab058a2f062b44132fc5426493607bef6bd496401b166eb0d554f29e67ee441c757908a2b6aead1a33d384ed54d88143a93f9
7
- data.tar.gz: ff535dee29861d258bd2ed365647958d7e9f2d77c4ae6ef8de7f6fa2f6fffc83e3e4926389461d40a3faa6bad70451b829474ea1975a2cdd66d0b226b90c6138
6
+ metadata.gz: a040b850d4d53c675680fcb870d1f266eef2e169b3ad87266a20cb6a39b5223a4b0a9032d9eedddc55596007b3e4b659abb43d55a42e31e712f8271543e4a5dd
7
+ data.tar.gz: 78fabfc6880a7e55a44264849b448de1eba16d44d37b7df1e18be4e0c820b24137a746329db0d7abb09be29c14d1570544dc5985d825253141476a04e51e665e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2021-03-21
4
-
5
- - Initial release
1
+ ## [v0.1.2]
2
+ - Support with default setting value in config/app.yml
3
+ ## [v0.1.1]
4
+ - Support mixin Symbol, Hash both with CUSTOM_RAILS_SETTINGS_KEYS
5
+ ## [v0.1.0]
6
+ - Custom rails setting cached with CUSTOM_RAILS_SETTINGS_KEYS
7
+ - Define accessor methods base on CUSTOM_RAILS_SETTINGS_KEYS
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- custom_rails_settings_cached (0.1.1)
4
+ custom_rails_settings_cached (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -43,6 +43,14 @@ Must define `CUSTOM_RAILS_SETTINGS_KEYS` before `include CustomRailsSettingsCach
43
43
  google_analytics: :tracking_code,
44
44
  facebook_pixel_ads: [:enabled, :tracking_code]
45
45
  }
46
+
47
+ # Or mixin
48
+
49
+ CUSTOM_RAILS_SETTINGS_KEYS = {
50
+ :title, :description,
51
+ google_analytics: [:enabled, :tracking_code],
52
+ facebook_pixel_ads: [:enabled, :tracking_code]
53
+ }
46
54
  ```
47
55
  Then, include `CustomRailsSettingsCached` in your model.
48
56
  Exam:
@@ -12,7 +12,7 @@ module CustomRailsSettingsCached
12
12
  def get_settings(name)
13
13
  if has_associations_with_rails_settings
14
14
  st = settings.find_by var: setting_key(name)
15
- st&.value
15
+ st ? st.value : default_value(name)
16
16
  else
17
17
  Setting[setting_key(name)]
18
18
  end
@@ -51,6 +51,11 @@ module CustomRailsSettingsCached
51
51
  @has_rails_settings = associations.any? { |a| a.name == :settings }
52
52
  end
53
53
 
54
+ def default_value(name)
55
+ default_setting_key = "#{self.class.name.to_s.underscore}.#{name.to_s.underscore}"
56
+ Setting[default_setting_key]
57
+ end
58
+
54
59
  if defined?(self::CUSTOM_RAILS_SETTINGS_KEYS)
55
60
  build_custom_settings_methods self::CUSTOM_RAILS_SETTINGS_KEYS
56
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CustomRailsSettingsCached
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
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-22 00:00:00.000000000 Z
11
+ date: 2021-03-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: My custom with Rails Settings Cached
14
14
  email: