feature_setting 1.3.2 → 1.3.3

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: 09b0b7bae749ff2478a13b992a2fa29a25f9c723
4
- data.tar.gz: 7f00fd0cc55537fc0843ddc4e1d231690f7f5fc6
3
+ metadata.gz: 4569619999399fd92cb877b3a7ce50e57577e658
4
+ data.tar.gz: 5b9a330d076941d0bd7e04ab19e9797fe72db1fe
5
5
  SHA512:
6
- metadata.gz: 3bbef1c397ec8189a1e41cb8fe4d84c351b791743ae9d0e7b862518d06d8610ccbf398eaa3c37078aa65be8ca1d6a57665bc164470b6031a2b30a88a7bf55f2e
7
- data.tar.gz: 210b9226a3439431d73d638d8efee7c19d5a4c2947af1e030e8fe9260c7131ff90ea794b622f1e875dece7a525f8233e28036edf58f2f4f1b0939e728ba28c4d
6
+ metadata.gz: cb6440f4203ed357381783cc7762f9d8caf6679e7b886c4bdd78c423f8cd6b491a96b3dfc89c91b56c7ff0be080a929e15f39a7d5ce3e69e24244e8057d0ab6f
7
+ data.tar.gz: a7e9cec6681cfe303c699fb7c3ae938b2326656b84ecd8d0e93c5e3874095e4759268f8165987a5d6aa9cff092058ebcfadd72bd0b29d045467ce68f97d942f3
data/README.md CHANGED
@@ -91,10 +91,12 @@ To create a new Setting class, inherit a class from `FeatureSetting::Setting` (i
91
91
  ```ruby
92
92
  class Settings < FeatureSetting::Setting
93
93
  SETTINGS = {
94
- setting_one: 12300,
95
- setting_two: 'some string',
94
+ setting_one: 12300,
95
+ setting_two: 'some string',
96
96
  setting_three: %w(one two three),
97
- setting_four: ENV['SETTING_FOUR']
97
+ setting_four: ENV['SETTING_FOUR'],
98
+ setting_five: { key1: 'value1', key2: 'value2' }
99
+ setting_six: true
98
100
  }
99
101
 
100
102
  init_settings!
@@ -104,18 +106,29 @@ end
104
106
  You can now do the following:
105
107
 
106
108
  ```ruby
107
- Settings.newsetting # => 500
108
- Settings.newsetting = 2000
109
- Settings.newsetting # => 2000
109
+ Settings.setting_one # => 12300
110
+ Settings.setting_one = 2000
111
+ Settings.setting_one # => 2000
110
112
 
111
113
  # other ways to set setting values:
112
- Settings.set!(newsetting: 1000)
113
- Settings.set!(:newsetting, 1000)
114
- Settings.set!('newsetting', 1000)
114
+ Settings.set!(setting_one: 1000)
115
+ Settings.set!(:setting_one, 1000)
116
+ Settings.set!('setting_one', 1000)
115
117
  ```
116
118
 
117
119
  Default values for settings are defined in your class and current values are persisted in the database.
118
120
 
121
+ Settings support the following datatypes:
122
+
123
+ ```
124
+ Boolean
125
+ String
126
+ Integer
127
+ Float
128
+ Symbol
129
+ Array
130
+ Hash
131
+ ```
119
132
 
120
133
  ### Advanced Features
121
134
 
@@ -1,4 +1,5 @@
1
1
  require 'active_record'
2
+ require 'json'
2
3
 
3
4
  module FeatureSetting
4
5
  class FsSetting < ActiveRecord::Base
@@ -85,9 +86,16 @@ module FeatureSetting
85
86
  end
86
87
 
87
88
  def convert_to_type(value, type)
89
+ p type
88
90
  case type
89
91
  when 'String'
90
92
  value.to_s
93
+ when 'TrueClass'
94
+ true
95
+ when 'NilClass'
96
+ false
97
+ when 'FalseClass'
98
+ false
91
99
  when 'Fixnum'
92
100
  value.to_i
93
101
  when 'Float'
@@ -96,11 +104,15 @@ module FeatureSetting
96
104
  value.to_sym
97
105
  when 'Array'
98
106
  value.split('|||')
107
+ when 'Hash'
108
+ JSON.parse(value).try(:symbolize_keys)
99
109
  end
100
110
  end
101
111
 
102
112
  def convert_to_string(value, type)
103
113
  case type
114
+ when 'Hash'
115
+ value.to_json
104
116
  when 'Array'
105
117
  value.join('|||')
106
118
  else
@@ -1,3 +1,3 @@
1
1
  module FeatureSetting
2
- VERSION = "1.3.2"
2
+ VERSION = "1.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feature_setting
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Indro De
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-02 00:00:00.000000000 Z
11
+ date: 2016-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport