ar-settings 0.1.0 → 0.2.0

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -7
  3. data/lib/settings.rb +14 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56924f917c516275dba8a8773afd52c159f749eb
4
- data.tar.gz: b3f5dfc5094fcd0f5e52d24ad16fb38a5bf3171d
3
+ metadata.gz: 514beb60ab432643297491c91545d87e947d8511
4
+ data.tar.gz: a46e908a7042f8e06cc808a3e5350a6904a08917
5
5
  SHA512:
6
- metadata.gz: 716ebc98fea93606872cf2f6a298b60e4a732d0bb75c4b646c04009c82dac2fa12bd3a4df7fc1280d461b55d3b0e17a75aa1fc81a8c162744eea2935a19f90f7
7
- data.tar.gz: 169db5a1b12170bb6fd884c4071e221212ea9cb507b0f965f471476eace3f2033faefc95655cdc2480888dfc31fbf998b16f6e5f0638d007fc678ba07405d25b
6
+ metadata.gz: eab67515991b4b247af548b9deb81aaca83356b7b03f3573f6b162ffde144f4658bdaed92240854b78de1d3931d8bcea5788b99d78a3df334ed7f42351933a81
7
+ data.tar.gz: 680617188cca46bd1f943527578f90cf2d6cbddd4a2b29023cad80d47df5729b6a0b3a963fcfe255288acde91fbc0bd3c951d33988be9fbae119354ac6c7d0c6
data/README.md CHANGED
@@ -18,18 +18,40 @@ $ rails generate install_settings
18
18
  ```
19
19
 
20
20
  ## Usage
21
- Gem implements minimal amount of public methods needed to manage settings:
21
+ Gem implements minimal amount of public methods needed to manage settings
22
+
23
+ ### Storing and fetching settings
24
+
25
+ ```rb
26
+ Settings.set(:key, 'value') # store a value
27
+ Settings.get(:key) # fetch a value
28
+ ```
29
+
30
+ ```rb
31
+ Settings.key = 'value' # equivalent to Settings.set(...)
32
+ Settings.key # equivalent to Settings.get(...)
33
+ ```
34
+
35
+ ### Mass update
36
+
37
+ Method convenient for handling settings form submission.
22
38
  ```rb
23
- Settings.set(:key, 'value')
24
- Settings.get(:key)
39
+ Settings.update({
40
+ key: 'value',
41
+ key2: 'value2',
42
+ ...
43
+ })
44
+ ```
25
45
 
26
- Settings.has(:key)
27
- Settings.unset(:key)
46
+ ### Additional methods
47
+ ```rb
48
+ Settings.has(:key) # check if setting field exists
49
+ Settings.unset(:key) # remove stored value if exists
28
50
  ```
29
51
 
52
+
30
53
  ## To do
31
- 1. Allow mass assignments
32
- 2. Utilize `Rails.cache` to reduce overhead of querying db
54
+ 1. Utilize `Rails.cache` to reduce overhead of querying db
33
55
 
34
56
  ## Licence
35
57
  Licensed under the MIT license.
@@ -17,4 +17,18 @@ class Settings < ActiveRecord::Base
17
17
  def self.unset(key)
18
18
  find_by(key: key)&.destroy
19
19
  end
20
+
21
+ def self.update(fields)
22
+ fields.each { |key, value| set(key, value) }
23
+ end
24
+
25
+ private
26
+
27
+ def self.method_missing(method_name, *arguments)
28
+ if method_name =~ /=$/
29
+ set method_name.to_s.gsub('=', ''), arguments.first
30
+ else
31
+ get method_name
32
+ end
33
+ end
20
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mladen Ilic