feature_setting 1.1.0 → 1.2.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7b74eb144e8d91a12cbb631bd244fd1a72e297c
|
4
|
+
data.tar.gz: aa980b19d5de36d71fac54e50194d012bd692785
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e68c43b11367ea876f0e58b257fc91a9e6fe283200ff1ee4bfd4a0a834ea80b5ebaf39fd4e7aa6cc76bc57d99d0fa09d177b2df47c6856b049d3496f2d3bf22
|
7
|
+
data.tar.gz: 84e9fe706f6f6eb614814cfe1ec5daf5b4e3f37ec458b8b8c281315e2268e6ec159f7940b4d014bca7f1087b67d602998c2844ae0930ebebebc4a45a7ffa2758
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v1.2.0
|
4
|
+
|
5
|
+
- change parent class names to `FeatureSetting::Feature` and `FeatureSetting::Setting` (the old `FsFeature` and `FsSetting` can still be used as well)
|
6
|
+
|
3
7
|
## v1.1.0
|
4
8
|
|
5
|
-
- dynamically generate setter methods for FsSetting keys simplify updating values:
|
9
|
+
- dynamically generate setter methods for FsSetting keys to simplify updating values:
|
6
10
|
|
7
11
|
```ruby
|
8
12
|
MySetting.setting_key = 123
|
data/README.md
CHANGED
@@ -7,9 +7,9 @@ This gem introduces the concept of "features" and "settings" to your Rails app.
|
|
7
7
|
- a feature is a key that can either be enabled or disabled
|
8
8
|
- a setting is a key that has a value (of type String, Fixnum, Float, or Array)
|
9
9
|
|
10
|
-
In practice, features can be used to switch certain functionality in your code on or off. This can be used to roll out functionality without the need to deploy. Settings are very flexible in that they can hold any value. The possibilities are endless.
|
10
|
+
In practice, features can be used to switch certain functionality in your code on or off. This can be used to roll out functionality without the need to deploy. Settings are very flexible in that they can hold any value. The possibilities are endless. They should not be used to store application secrets, such as tokens, passwords, and keys. Those type of settings should rather be stored in environment variables using tools like [https://github.com/bkeepers/dotenv](dotenv).
|
11
11
|
|
12
|
-
Both, features and settings are configured with default values
|
12
|
+
Both, features and settings are configured in your code with default values. They can then be updated at any time in the Rails console and persist in the database.
|
13
13
|
|
14
14
|
```ruby
|
15
15
|
# using features:
|
@@ -52,10 +52,10 @@ The next step is to define your Feature and/or Setting classes.
|
|
52
52
|
|
53
53
|
### Features
|
54
54
|
|
55
|
-
To create a new Feature class, inherit a class from `FeatureSetting::FsFeature
|
55
|
+
To create a new Feature class, inherit a class from `FeatureSetting::Feature` (if using a gem version prior to `1.2.0` use `FeatureSetting::FsFeature`). Then define your features in a hash called `FEATURES` and call `init_features!`.
|
56
56
|
|
57
57
|
```ruby
|
58
|
-
class Features < FeatureSetting::
|
58
|
+
class Features < FeatureSetting::Feature
|
59
59
|
FEATURES = {
|
60
60
|
newfeature: true
|
61
61
|
}
|
@@ -81,15 +81,15 @@ Features.enable_newfeature!
|
|
81
81
|
Features.disable_newfeature!
|
82
82
|
```
|
83
83
|
|
84
|
-
Default values for features are defined in your class and
|
84
|
+
Default values for features are defined in your class and current values are persisted in the database.
|
85
85
|
|
86
86
|
|
87
87
|
### Settings
|
88
88
|
|
89
|
-
To create a new Setting class, inherit a class from `FeatureSetting::FsSetting
|
89
|
+
To create a new Setting class, inherit a class from `FeatureSetting::Setting` (if using a gem version prior to `1.2.0` use `FeatureSetting::FsSetting`). Then define your settings in a hash called `SETTINGS` and call `init_settings!`. The following example shows the setup and some possible definitions.
|
90
90
|
|
91
91
|
```ruby
|
92
|
-
class Settings < FeatureSetting::
|
92
|
+
class Settings < FeatureSetting::Setting
|
93
93
|
SETTINGS = {
|
94
94
|
setting_one: 12300,
|
95
95
|
setting_two: 'some string',
|
@@ -26,18 +26,26 @@ module FeatureSetting
|
|
26
26
|
def init_settings!
|
27
27
|
settings.each do |key, value|
|
28
28
|
self.create_with(key: key, value: convert_to_string(value, value.class.to_s), value_type: value.class.to_s, klass: klass).find_or_create_by(klass: klass, key: key)
|
29
|
-
|
30
|
-
|
31
|
-
convert_to_type(record.value, record.value_type)
|
32
|
-
end
|
33
|
-
define_singleton_method("#{key}=") do |value|
|
34
|
-
record = self.where(key: key, klass: klass).first
|
35
|
-
set!(key, value)
|
36
|
-
end
|
29
|
+
define_getter_method(key)
|
30
|
+
define_setter_method(key)
|
37
31
|
end
|
38
32
|
remove_old_settings!
|
39
33
|
end
|
40
34
|
|
35
|
+
def define_getter_method(key)
|
36
|
+
define_singleton_method(key.to_s) do
|
37
|
+
record = self.where(key: key, klass: klass).first
|
38
|
+
convert_to_type(record.value, record.value_type)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_setter_method(key)
|
43
|
+
define_singleton_method("#{key}=") do |value|
|
44
|
+
record = self.where(key: key, klass: klass).first
|
45
|
+
set!(key, value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
41
49
|
def remove_old_settings!
|
42
50
|
self.where(klass: klass, key: all_stored_settings - defined_settings).destroy_all
|
43
51
|
end
|
@@ -99,4 +107,7 @@ module FeatureSetting
|
|
99
107
|
end
|
100
108
|
end
|
101
109
|
end
|
110
|
+
|
111
|
+
# alias this class to Setting
|
112
|
+
Setting = FsSetting
|
102
113
|
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.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Indro De
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|