settingson 1.5.14 → 1.6.0

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
  SHA1:
3
- metadata.gz: 1e51070968a75427fd22aaf7f1d5ad0c0e67224c
4
- data.tar.gz: 4d4a8ba87b4c9c30f00c3b54cadc97f65ed2ced4
3
+ metadata.gz: f3c4ea80ad5fe66fef73ce4715f535030f1836bf
4
+ data.tar.gz: c42f01d41f391c94da05d0b13ab37ced34f562db
5
5
  SHA512:
6
- metadata.gz: 1ad608ad7214de9ff8c8a03aefea29595d5bf8680771d860ecdb010c2ea77f45e1d582a955d0a602edc11de59dd3e03d29bb355615f9686a4bf199ee0c531c51
7
- data.tar.gz: d832c44e479667e036cc6a5e65f46c77a7e976c1701c47188a58862d3cadf92b74bee5e266e59a327f016d5dea490dd440c2f5633df8e156143d5096068238fb
6
+ metadata.gz: 2d1e7603d60e6a47402f5d332b1fff7eb4e6905610329068fac2211040508862b689847a866fb4ea00ce4a8d28d883445d2a4345ff25891fa90ba2d537ad6bfd
7
+ data.tar.gz: ca5dffb1c631e00f8a25d7bb706e64b075eadf3c07678b272400fc78ebf9d7b55d992c2706aa32fa1955ee9aa1a8401bca05f45d5d7490f2ac4b8d58cafe1cfa
@@ -75,13 +75,17 @@ module Settingson::Base
75
75
  included do
76
76
  attr_accessor :settingson
77
77
  serialize :value
78
- before_destroy :delete_cached
78
+ before_destroy :__delete_cached
79
79
  end
80
80
 
81
- def delete_cached
81
+ def __debug(message)
82
+ Rails.logger.debug(message) if self.class.configure.debug
83
+ end
84
+
85
+ def __delete_cached
82
86
  cache_key = "#{self.class.configure.cache.namespace}/#{self.key}"
83
87
  Rails.cache.delete(cache_key)
84
- Rails.logger.debug("#{self.class.name}: delete '#{self.key}' '#{cache_key}'")
88
+ __debug("#{self.class.name}: delete '#{self.key}' '#{cache_key}'")
85
89
  end
86
90
 
87
91
  def to_s
@@ -105,51 +109,51 @@ module Settingson::Base
105
109
  def method_missing(symbol, *args)
106
110
  super
107
111
  rescue NameError
108
- rescue_action(symbol.to_s, args.first)
112
+ __rescue_action(symbol.to_s, args.first)
109
113
  rescue NoMethodError
110
- rescue_action(symbol.to_s, args.first)
114
+ __rescue_action(symbol.to_s, args.first)
111
115
  end # method_missing
112
116
 
113
117
  protected
114
118
 
115
- def cached_key
119
+ def __cached_key
116
120
  [ self.class.configure.cache.namespace, @settingson ].join('/')
117
121
  end
118
122
 
119
- def rescue_action(key, value)
123
+ def __rescue_action(key, value)
120
124
  case key
121
125
  when /(.+)=/ # setter
122
126
  @settingson = [@settingson, $1].compact.join('.')
123
127
  record = self.class.find_or_create_by!(key: @settingson)
124
128
  record.update!(value: value)
125
- Rails.cache.write(cached_key, value)
126
- Rails.logger.debug("#{self.class.name}##{__method__} setter '#{cached_key}'")
129
+ Rails.cache.write(__cached_key, value)
130
+ __debug("#{self.class.name}##{__method__} setter '#{__cached_key}'")
127
131
  record.value
128
132
  else # returns values or self
129
133
  @settingson = [@settingson, key].compact.join('.')
130
- Rails.logger.debug("#{self.class.name}##{__method__} getter '#{@settingson}'")
131
- cached_value_or_self
134
+ __debug("#{self.class.name}##{__method__} getter '#{@settingson}'")
135
+ __cached_value_or_self
132
136
  end
133
137
  end
134
138
 
135
- def cached_value_or_self
136
- result = cached_value
139
+ def __cached_value_or_self
140
+ result = __cached_value
137
141
  result.is_a?(ActiveRecord::RecordNotFound) ? self : result
138
142
  end
139
143
 
140
- def cached_value
141
- Rails.logger.debug("#{self.class.name}##{__method__} '#{@settingson}'")
144
+ def __cached_value
145
+ __debug("#{self.class.name}##{__method__} '#{@settingson}'")
142
146
  Rails.cache.fetch(
143
- cached_key,
147
+ __cached_key,
144
148
  expires_in: self.class.configure.cache.expires,
145
149
  race_condition_ttl: self.class.configure.cache.race_condition_ttl
146
150
  ) do
147
- Rails.logger.debug("#{self.class.name}: fresh '#{@settingson}'")
148
- fresh_value
151
+ __debug("#{self.class.name}: fresh '#{@settingson}'")
152
+ __fresh_value
149
153
  end
150
154
  end
151
155
 
152
- def fresh_value
156
+ def __fresh_value
153
157
  self.class.find_by!(key: @settingson).value
154
158
  rescue ActiveRecord::RecordNotFound
155
159
  ActiveRecord::RecordNotFound.new
@@ -1,7 +1,9 @@
1
1
  class Settingson::Config
2
2
  attr_accessor :cache
3
+ attr_accessor :debug
3
4
 
4
5
  def initialize
6
+ @debug = false
5
7
  @cache = OpenStruct.new(expires_in: 60.seconds,
6
8
  race_condition_ttl: 10.seconds,
7
9
  enabled: true,
@@ -1,3 +1,3 @@
1
1
  module Settingson
2
- VERSION = "1.5.14"
2
+ VERSION = "1.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settingson
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.14
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dan