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: 18ca75fc887ba02f7803b8702d72c8adc720cf80
4
- data.tar.gz: 1c4a9ac3f0697cca4f6784bcd34ab9395f39f94e
3
+ metadata.gz: d7b74eb144e8d91a12cbb631bd244fd1a72e297c
4
+ data.tar.gz: aa980b19d5de36d71fac54e50194d012bd692785
5
5
  SHA512:
6
- metadata.gz: 5387df7acbec72b6d024fd3b542674276829f751df3f38218c59689ef9a76554b2c97ee7e206432be88aed1ed1324a478caf9c3b2b60a5e0162475d84801d633
7
- data.tar.gz: 7becbfd04f2cb502cdd0d1400a09b06e608594d482320b7c50bd5daf0e0aff224d784d8c2426f43147c2e76c2656bb0d502ffd5b0b007a839c2090d170418f2f
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 that persist in the database and then can be updated if required.
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`. Then define your features in th `FEATURES` hash and call `init_features!`.
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::FsFeature
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 current values are persisted in the database.
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`. Then define your settings in the `SETTINGS` hash and call `init_settings!`. The following example shows some possible definitions.
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::FsSetting
92
+ class Settings < FeatureSetting::Setting
93
93
  SETTINGS = {
94
94
  setting_one: 12300,
95
95
  setting_two: 'some string',
@@ -74,4 +74,7 @@ module FeatureSetting
74
74
  end
75
75
  end
76
76
  end
77
+
78
+ # alias this class to Feature
79
+ Feature = FsFeature
77
80
  end
@@ -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
- define_singleton_method(key.to_s) do
30
- record = self.where(key: key, klass: klass).first
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
@@ -1,3 +1,3 @@
1
1
  module FeatureSetting
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
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.1.0
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-06-30 00:00:00.000000000 Z
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport