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 +4 -4
- data/README.md +22 -9
- data/lib/feature_setting/orm/active_record/fs_setting.rb +12 -0
- data/lib/feature_setting/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4569619999399fd92cb877b3a7ce50e57577e658
|
4
|
+
data.tar.gz: 5b9a330d076941d0bd7e04ab19e9797fe72db1fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
95
|
-
setting_two:
|
94
|
+
setting_one: 12300,
|
95
|
+
setting_two: 'some string',
|
96
96
|
setting_three: %w(one two three),
|
97
|
-
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.
|
108
|
-
Settings.
|
109
|
-
Settings.
|
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!(
|
113
|
-
Settings.set!(:
|
114
|
-
Settings.set!('
|
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
|
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.
|
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-
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|