feature_setting 1.6.3 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +100 -0
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/bin/console +3 -3
- data/feature_setting.gemspec +22 -15
- data/lib/feature_setting/orm/active_record/fs_feature.rb +47 -31
- data/lib/feature_setting/orm/active_record/fs_setting.rb +48 -55
- data/lib/feature_setting/version.rb +1 -1
- data/lib/generators/feature_setting/install/install_generator.rb +1 -1
- data/lib/helpers/convert_value.rb +37 -0
- metadata +55 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d88b8c501d738b622e547956bbbc2e44164e375d72fe949a02749a5dbba93207
|
4
|
+
data.tar.gz: 5ae3b3db98a22c65a7595b4b14015fae8b3b3de9f3c08d506186bb27a2c03657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e97a3af42489cc34a2b4c716b6c36d241eb834156aa0936358cc57b0fb7d387fcfdea6f11d7b01f4e8c7551174d4b37a69800831f5927ae82f0c4f9d58809442
|
7
|
+
data.tar.gz: 6954b1cb38e3314b9cf0f63181c0e6e100ad0e7ed647fa969e6cd71b67b15326ad60092a9de4159035b5e22068b444559d4b2b21831cfff5a9e54e4cfb9996ea
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.6
|
7
|
+
Style/FrozenStringLiteralComment:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/BlockLength:
|
10
|
+
Exclude:
|
11
|
+
- 'spec/**/*'
|
12
|
+
- 'feature_setting.gemspec'
|
13
|
+
RSpec/MultipleExpectations:
|
14
|
+
Max: 3
|
15
|
+
RSpec/ExampleLength:
|
16
|
+
Max: 10
|
17
|
+
RSpec/MessageSpies:
|
18
|
+
EnforcedStyle: receive
|
19
|
+
Style/Documentation:
|
20
|
+
Enabled: false
|
21
|
+
Metrics/ClassLength:
|
22
|
+
Max: 105
|
23
|
+
Metrics/MethodLength:
|
24
|
+
Max: 12
|
25
|
+
Exclude:
|
26
|
+
- 'lib/generators/**/**'
|
27
|
+
RSpec/FilePath:
|
28
|
+
Enabled: false
|
29
|
+
Gemspec/DateAssignment: # (new in 1.10)
|
30
|
+
Enabled: true
|
31
|
+
Layout/SpaceBeforeBrackets: # (new in 1.7)
|
32
|
+
Enabled: true
|
33
|
+
Lint/AmbiguousAssignment: # (new in 1.7)
|
34
|
+
Enabled: true
|
35
|
+
Lint/DeprecatedConstants: # (new in 1.8)
|
36
|
+
Enabled: true
|
37
|
+
Lint/DuplicateBranch: # (new in 1.3)
|
38
|
+
Enabled: true
|
39
|
+
Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
|
40
|
+
Enabled: true
|
41
|
+
Lint/EmptyBlock: # (new in 1.1)
|
42
|
+
Enabled: true
|
43
|
+
Lint/EmptyClass: # (new in 1.3)
|
44
|
+
Enabled: true
|
45
|
+
Lint/EmptyInPattern: # (new in 1.16)
|
46
|
+
Enabled: true
|
47
|
+
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
|
48
|
+
Enabled: true
|
49
|
+
Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
|
50
|
+
Enabled: true
|
51
|
+
Lint/NumberedParameterAssignment: # (new in 1.9)
|
52
|
+
Enabled: true
|
53
|
+
Lint/OrAssignmentToConstant: # (new in 1.9)
|
54
|
+
Enabled: true
|
55
|
+
Lint/RedundantDirGlobSort: # (new in 1.8)
|
56
|
+
Enabled: true
|
57
|
+
Lint/SymbolConversion: # (new in 1.9)
|
58
|
+
Enabled: true
|
59
|
+
Lint/ToEnumArguments: # (new in 1.1)
|
60
|
+
Enabled: true
|
61
|
+
Lint/TripleQuotes: # (new in 1.9)
|
62
|
+
Enabled: true
|
63
|
+
Lint/UnexpectedBlockArity: # (new in 1.5)
|
64
|
+
Enabled: true
|
65
|
+
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
|
66
|
+
Enabled: true
|
67
|
+
Style/ArgumentsForwarding: # (new in 1.1)
|
68
|
+
Enabled: true
|
69
|
+
Style/CollectionCompact: # (new in 1.2)
|
70
|
+
Enabled: true
|
71
|
+
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
|
72
|
+
Enabled: true
|
73
|
+
Style/EndlessMethod: # (new in 1.8)
|
74
|
+
Enabled: true
|
75
|
+
Style/HashConversion: # (new in 1.10)
|
76
|
+
Enabled: true
|
77
|
+
Style/HashExcept: # (new in 1.7)
|
78
|
+
Enabled: true
|
79
|
+
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
|
80
|
+
Enabled: true
|
81
|
+
Style/InPatternThen: # (new in 1.16)
|
82
|
+
Enabled: true
|
83
|
+
Style/MultilineInPatternThen: # (new in 1.16)
|
84
|
+
Enabled: true
|
85
|
+
Style/NegatedIfElseCondition: # (new in 1.2)
|
86
|
+
Enabled: true
|
87
|
+
Style/NilLambda: # (new in 1.3)
|
88
|
+
Enabled: true
|
89
|
+
Style/QuotedSymbols: # (new in 1.16)
|
90
|
+
Enabled: true
|
91
|
+
Style/RedundantArgument: # (new in 1.4)
|
92
|
+
Enabled: true
|
93
|
+
Style/StringChars: # (new in 1.12)
|
94
|
+
Enabled: true
|
95
|
+
Style/SwapValues: # (new in 1.1)
|
96
|
+
Enabled: true
|
97
|
+
RSpec/IdenticalEqualityAssertion: # (new in 2.4)
|
98
|
+
Enabled: true
|
99
|
+
RSpec/Rails/AvoidSetupHook: # (new in 2.4)
|
100
|
+
Enabled: true
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# feature_setting
|
2
2
|
|
3
3
|
[![Gem
|
4
|
-
Version](https://badge.fury.io/rb/feature_setting.svg)](
|
4
|
+
Version](https://badge.fury.io/rb/feature_setting.svg)](https://badge.fury.io/rb/feature_setting)
|
5
5
|
[![Code
|
6
6
|
Climate](https://codeclimate.com/github/indrode/feature_setting/badges/gpa.svg)](https://codeclimate.com/github/indrode/feature_setting)
|
7
7
|
[![Test
|
@@ -30,8 +30,8 @@ if Setting.error_threshold > 500
|
|
30
30
|
# do this
|
31
31
|
end
|
32
32
|
|
33
|
-
if Setting.allowed_users.include?(current_user)
|
34
|
-
#
|
33
|
+
if Setting.allowed_users.include?(current_user.id)
|
34
|
+
# do that
|
35
35
|
end
|
36
36
|
```
|
37
37
|
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'feature_setting'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "feature_setting"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/feature_setting.gemspec
CHANGED
@@ -1,29 +1,36 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'feature_setting/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.
|
8
|
-
spec.
|
9
|
-
spec.
|
10
|
-
spec.
|
11
|
-
spec.
|
6
|
+
spec.required_ruby_version = '>= 2.6.0'
|
7
|
+
spec.name = 'feature_setting'
|
8
|
+
spec.version = FeatureSetting::VERSION
|
9
|
+
spec.licenses = ['MIT']
|
10
|
+
spec.authors = ['Indro De']
|
11
|
+
spec.email = ['indro.de@gmail.com']
|
12
12
|
|
13
|
-
spec.summary
|
14
|
-
spec.description
|
15
|
-
|
13
|
+
spec.summary = 'A lightweight feature/setting DSL for Rails applications.'
|
14
|
+
spec.description = <<-DESCRIPTION
|
15
|
+
This gem introduces the concept of "features" and "settings" to your Rails app.
|
16
|
+
It provides an easy way to define such features and settings with default values
|
17
|
+
right in your code and will persist them in the database.
|
18
|
+
DESCRIPTION
|
19
|
+
spec.homepage = 'https://github.com/indrode/feature_setting'
|
16
20
|
|
17
|
-
spec.files
|
18
|
-
spec.require_paths
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.require_paths = ['lib']
|
19
23
|
|
20
|
-
spec.add_runtime_dependency 'activesupport', '>= 4.0'
|
21
24
|
spec.add_runtime_dependency 'activerecord', '>= 4.0'
|
25
|
+
spec.add_runtime_dependency 'activesupport', '>= 4.0'
|
22
26
|
spec.add_runtime_dependency 'hashie', '>= 3.4.3'
|
23
27
|
spec.add_development_dependency 'bundler', '>= 1.9'
|
28
|
+
spec.add_development_dependency 'byebug'
|
24
29
|
spec.add_development_dependency 'rake', '>= 10.0'
|
25
30
|
spec.add_development_dependency 'rspec', '>= 3.0'
|
26
|
-
spec.add_development_dependency '
|
27
|
-
spec.add_development_dependency '
|
31
|
+
spec.add_development_dependency 'rubocop', '>= 1.17.0'
|
32
|
+
spec.add_development_dependency 'rubocop-rake'
|
33
|
+
spec.add_development_dependency 'rubocop-rspec'
|
28
34
|
spec.add_development_dependency 'simplecov'
|
35
|
+
spec.add_development_dependency 'sqlite3'
|
29
36
|
end
|
@@ -4,7 +4,7 @@ module FeatureSetting
|
|
4
4
|
class FsFeature < ActiveRecord::Base
|
5
5
|
FEATURES = {
|
6
6
|
test: false
|
7
|
-
}
|
7
|
+
}.freeze
|
8
8
|
|
9
9
|
def features
|
10
10
|
self.class::FEATURES
|
@@ -15,25 +15,25 @@ module FeatureSetting
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class << self
|
18
|
-
def method_missing(
|
18
|
+
def method_missing(_method, *_args)
|
19
19
|
false
|
20
20
|
end
|
21
21
|
|
22
|
-
def respond_to_missing?(*
|
22
|
+
def respond_to_missing?(*_args)
|
23
23
|
true
|
24
24
|
end
|
25
25
|
|
26
26
|
def features
|
27
|
-
|
27
|
+
new.features
|
28
28
|
end
|
29
29
|
|
30
30
|
def klass
|
31
|
-
|
31
|
+
new.klass.to_s
|
32
32
|
end
|
33
33
|
|
34
|
-
def init_features!(remove_old_features
|
34
|
+
def init_features!(remove_old_features: false)
|
35
35
|
features.each do |key, value|
|
36
|
-
|
36
|
+
create_feature(key, value)
|
37
37
|
define_checker_method(key)
|
38
38
|
define_enabler_method(key)
|
39
39
|
define_disabler_method(key)
|
@@ -43,8 +43,8 @@ module FeatureSetting
|
|
43
43
|
|
44
44
|
def cache_features!
|
45
45
|
features.each do |key, value|
|
46
|
-
|
47
|
-
value =
|
46
|
+
create_feature(key, value)
|
47
|
+
value = find_by(key: key, klass: klass).enabled
|
48
48
|
define_checker_method(key) { value }
|
49
49
|
define_enabler_method(key) { false }
|
50
50
|
define_disabler_method(key) { false }
|
@@ -52,48 +52,53 @@ module FeatureSetting
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def define_checker_method(key, &block)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
unless block_given?
|
56
|
+
block = proc do
|
57
|
+
record = find_by key: key, klass: klass
|
58
|
+
record ? record.enabled : false
|
59
|
+
end
|
60
|
+
end
|
59
61
|
define_singleton_method("#{key}_enabled?") { block.call }
|
60
62
|
end
|
61
63
|
|
62
64
|
def define_enabler_method(key, &block)
|
63
|
-
|
64
|
-
|
65
|
-
|
65
|
+
unless block_given?
|
66
|
+
block = proc do
|
67
|
+
enable!(key)
|
68
|
+
end
|
69
|
+
end
|
66
70
|
define_singleton_method("enable_#{key}!") { block.call }
|
67
71
|
end
|
68
72
|
|
69
73
|
def define_disabler_method(key, &block)
|
70
|
-
|
71
|
-
|
72
|
-
|
74
|
+
unless block_given?
|
75
|
+
block = proc do
|
76
|
+
disable!(key)
|
77
|
+
end
|
78
|
+
end
|
73
79
|
define_singleton_method("disable_#{key}!") { block.call }
|
74
80
|
end
|
75
81
|
|
76
82
|
def remove_old_features!
|
77
|
-
|
83
|
+
where(key: all_stored_features - defined_features).destroy_all
|
78
84
|
end
|
79
85
|
|
80
86
|
def reset_features!
|
81
|
-
|
82
|
-
init_features!
|
87
|
+
init_features! if where(klass: klass).delete_all
|
83
88
|
end
|
84
89
|
|
85
90
|
def enable!(key)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
91
|
+
return unless features.key?(key.to_sym)
|
92
|
+
|
93
|
+
record = find_by key: key, klass: klass
|
94
|
+
record.update(enabled: true)
|
90
95
|
end
|
91
96
|
|
92
97
|
def disable!(key)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
98
|
+
return unless features.key?(key.to_sym)
|
99
|
+
|
100
|
+
record = find_by key: key, klass: klass
|
101
|
+
record.update(enabled: false)
|
97
102
|
end
|
98
103
|
|
99
104
|
def defined_features
|
@@ -103,7 +108,18 @@ module FeatureSetting
|
|
103
108
|
private
|
104
109
|
|
105
110
|
def all_stored_features
|
106
|
-
|
111
|
+
all.pluck(:key)
|
112
|
+
end
|
113
|
+
|
114
|
+
def create_feature(key, value)
|
115
|
+
create_with(
|
116
|
+
key: key,
|
117
|
+
enabled: value,
|
118
|
+
klass: klass
|
119
|
+
).find_or_create_by(
|
120
|
+
klass: klass,
|
121
|
+
key: key
|
122
|
+
)
|
107
123
|
end
|
108
124
|
end
|
109
125
|
end
|
@@ -1,8 +1,21 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'json'
|
3
|
+
require_relative './../../../helpers/convert_value'
|
3
4
|
|
4
5
|
module FeatureSetting
|
5
6
|
class FsSetting < ActiveRecord::Base
|
7
|
+
class SettingKeyNotFoundError < StandardError
|
8
|
+
def message
|
9
|
+
'Key is missing or does not exist.'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class SettingTypeMismatchError < StandardError
|
14
|
+
def message
|
15
|
+
'The value for a setting of type Hash must be a Hash.'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
6
19
|
SETTINGS = {
|
7
20
|
test: 'value'
|
8
21
|
}.freeze
|
@@ -24,9 +37,9 @@ module FeatureSetting
|
|
24
37
|
new.klass.to_s
|
25
38
|
end
|
26
39
|
|
27
|
-
def init_settings!(remove_old_settings
|
40
|
+
def init_settings!(remove_old_settings: false)
|
28
41
|
settings.each do |key, value|
|
29
|
-
|
42
|
+
create_setting(key, value)
|
30
43
|
define_getter_method(key)
|
31
44
|
define_setter_method(key)
|
32
45
|
end
|
@@ -35,18 +48,20 @@ module FeatureSetting
|
|
35
48
|
|
36
49
|
def cache_settings!
|
37
50
|
settings.each do |key, value|
|
38
|
-
|
39
|
-
record =
|
40
|
-
value = convert_to_type(record.value, record.value_type)
|
51
|
+
create_setting(key, value)
|
52
|
+
record = find_by key: key, klass: klass
|
53
|
+
value = ConvertValue.convert_to_type(record.value, record.value_type)
|
41
54
|
define_getter_method(key) { value }
|
42
55
|
end
|
43
56
|
end
|
44
57
|
|
45
58
|
def define_getter_method(key, &block)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
59
|
+
unless block_given?
|
60
|
+
block = proc do
|
61
|
+
record = find_by key: key, klass: klass
|
62
|
+
ConvertValue.convert_to_type(record.value, record.value_type)
|
63
|
+
end
|
64
|
+
end
|
50
65
|
|
51
66
|
define_singleton_method(key.to_s) { block.call }
|
52
67
|
end
|
@@ -58,22 +73,22 @@ module FeatureSetting
|
|
58
73
|
end
|
59
74
|
|
60
75
|
def remove_old_settings!
|
61
|
-
where(klass: klass, key: all_stored_keys - defined_keys).
|
76
|
+
where(klass: klass, key: all_stored_keys - defined_keys).delete_all
|
62
77
|
end
|
63
78
|
|
64
79
|
def reset_settings!
|
65
|
-
where(klass: klass).
|
66
|
-
init_settings!
|
80
|
+
init_settings! if where(klass: klass).delete_all
|
67
81
|
end
|
68
82
|
|
83
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
69
84
|
def set!(key = nil, value = nil)
|
70
|
-
raise
|
85
|
+
raise SettingNotExistsError unless defined_keys.include?(key.to_s)
|
71
86
|
|
72
|
-
record =
|
73
|
-
old_value = convert_to_type(record.value, record.value_type)
|
87
|
+
record = find_by key: key.to_s, klass: klass
|
88
|
+
old_value = ConvertValue.convert_to_type(record.value, record.value_type)
|
74
89
|
|
75
90
|
if record.value_type == 'Hash'
|
76
|
-
raise
|
91
|
+
raise SettingTypeMismatchError unless value.is_a?(Hash)
|
77
92
|
|
78
93
|
new_value = old_value.update(value)
|
79
94
|
value_type = 'Hash'
|
@@ -83,16 +98,18 @@ module FeatureSetting
|
|
83
98
|
end
|
84
99
|
|
85
100
|
record.update(
|
86
|
-
value: convert_to_string(new_value, new_value.class.to_s),
|
101
|
+
value: ConvertValue.convert_to_string(new_value, new_value.class.to_s),
|
87
102
|
value_type: value_type
|
88
103
|
)
|
89
104
|
end
|
90
|
-
|
105
|
+
alias update! set!
|
106
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
91
107
|
|
92
108
|
def existing_key(key = nil, hash = {})
|
93
|
-
settings.key?(hash.keys.first) || settings.key?(key.to_sym)
|
109
|
+
return unless settings.key?(hash.keys.first) || settings.key?(key.to_sym)
|
110
|
+
|
94
111
|
hash.keys.first || key.to_sym
|
95
|
-
rescue
|
112
|
+
rescue StandardError
|
96
113
|
nil
|
97
114
|
end
|
98
115
|
|
@@ -103,7 +120,7 @@ module FeatureSetting
|
|
103
120
|
def stored_settings
|
104
121
|
hash = {}
|
105
122
|
where(klass: klass).each do |record|
|
106
|
-
hash[record.key.to_sym] = convert_to_type(record.value, record.value_type)
|
123
|
+
hash[record.key.to_sym] = ConvertValue.convert_to_type(record.value, record.value_type)
|
107
124
|
end
|
108
125
|
|
109
126
|
hash
|
@@ -115,40 +132,16 @@ module FeatureSetting
|
|
115
132
|
all.pluck(:key)
|
116
133
|
end
|
117
134
|
|
118
|
-
def
|
119
|
-
|
120
|
-
|
121
|
-
value.to_s
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
when 'Fixnum'
|
129
|
-
value.to_i
|
130
|
-
when 'Integer'
|
131
|
-
value.to_i
|
132
|
-
when 'Float'
|
133
|
-
value.to_f
|
134
|
-
when 'Symbol'
|
135
|
-
value.to_sym
|
136
|
-
when 'Array'
|
137
|
-
value.split('|||')
|
138
|
-
when 'Hash'
|
139
|
-
Hashie::Mash.new(JSON.parse(value))
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def convert_to_string(value, type)
|
144
|
-
case type
|
145
|
-
when 'Hash', 'Hashie::Mash'
|
146
|
-
value.to_json
|
147
|
-
when 'Array'
|
148
|
-
value.join('|||')
|
149
|
-
else
|
150
|
-
value.to_s
|
151
|
-
end
|
135
|
+
def create_setting(key, value)
|
136
|
+
create_with(
|
137
|
+
key: key,
|
138
|
+
value: ConvertValue.convert_to_string(value, value.class.to_s),
|
139
|
+
value_type: value.class.to_s,
|
140
|
+
klass: klass
|
141
|
+
).find_or_create_by(
|
142
|
+
klass: klass,
|
143
|
+
key: key
|
144
|
+
)
|
152
145
|
end
|
153
146
|
end
|
154
147
|
end
|
@@ -13,7 +13,7 @@ module FeatureSetting
|
|
13
13
|
end
|
14
14
|
|
15
15
|
desc 'Generates database tables for feature_settings'
|
16
|
-
source_root File.expand_path('
|
16
|
+
source_root File.expand_path('templates', __dir__)
|
17
17
|
|
18
18
|
def create_migrations
|
19
19
|
migration_name = 'create_fs_tables.rb'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ConvertValue
|
2
|
+
class << self
|
3
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
4
|
+
def convert_to_type(value, type)
|
5
|
+
case type
|
6
|
+
when 'String'
|
7
|
+
value.to_s
|
8
|
+
when 'TrueClass'
|
9
|
+
true
|
10
|
+
when 'NilClass', 'FalseClass'
|
11
|
+
false
|
12
|
+
when 'Fixnum', 'Integer'
|
13
|
+
value.to_i
|
14
|
+
when 'Float'
|
15
|
+
value.to_f
|
16
|
+
when 'Symbol'
|
17
|
+
value.to_sym
|
18
|
+
when 'Array'
|
19
|
+
value.split('|||')
|
20
|
+
when 'Hash'
|
21
|
+
Hashie::Mash.new(JSON.parse(value))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
25
|
+
|
26
|
+
def convert_to_string(value, type)
|
27
|
+
case type
|
28
|
+
when 'Hash', 'Hashie::Mash'
|
29
|
+
value.to_json
|
30
|
+
when 'Array'
|
31
|
+
value.join('|||')
|
32
|
+
else
|
33
|
+
value.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feature_setting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.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: 2021-
|
11
|
+
date: 2021-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +109,21 @@ dependencies:
|
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '3.0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.17.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.17.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-rake
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
129
|
- - ">="
|
@@ -109,7 +137,7 @@ dependencies:
|
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '0'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
140
|
+
name: rubocop-rspec
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
114
142
|
requirements:
|
115
143
|
- - ">="
|
@@ -136,9 +164,24 @@ dependencies:
|
|
136
164
|
- - ">="
|
137
165
|
- !ruby/object:Gem::Version
|
138
166
|
version: '0'
|
139
|
-
|
140
|
-
|
141
|
-
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: sqlite3
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: |2
|
182
|
+
This gem introduces the concept of "features" and "settings" to your Rails app.
|
183
|
+
It provides an easy way to define such features and settings with default values
|
184
|
+
right in your code and will persist them in the database.
|
142
185
|
email:
|
143
186
|
- indro.de@gmail.com
|
144
187
|
executables: []
|
@@ -147,6 +190,7 @@ extra_rdoc_files: []
|
|
147
190
|
files:
|
148
191
|
- ".gitignore"
|
149
192
|
- ".rspec"
|
193
|
+
- ".rubocop.yml"
|
150
194
|
- ".travis.yml"
|
151
195
|
- CHANGELOG.md
|
152
196
|
- Gemfile
|
@@ -162,6 +206,7 @@ files:
|
|
162
206
|
- lib/feature_setting/version.rb
|
163
207
|
- lib/generators/feature_setting/install/install_generator.rb
|
164
208
|
- lib/generators/feature_setting/install/templates/migrations/create_fs_tables.rb
|
209
|
+
- lib/helpers/convert_value.rb
|
165
210
|
homepage: https://github.com/indrode/feature_setting
|
166
211
|
licenses:
|
167
212
|
- MIT
|
@@ -174,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
219
|
requirements:
|
175
220
|
- - ">="
|
176
221
|
- !ruby/object:Gem::Version
|
177
|
-
version:
|
222
|
+
version: 2.6.0
|
178
223
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
224
|
requirements:
|
180
225
|
- - ">="
|