ledermann-rails-settings 2.4.3 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -63
- data/MIT-LICENSE +1 -1
- data/README.md +27 -7
- data/ci/Gemfile-rails-4-2 +2 -1
- data/ci/Gemfile-rails-5-0 +2 -1
- data/ci/Gemfile-rails-5-1 +2 -1
- data/ci/Gemfile-rails-5-2 +2 -1
- data/ci/{Gemfile-rails-3-1 → Gemfile-rails-6-0} +2 -1
- data/lib/rails-settings.rb +1 -3
- data/lib/rails-settings/configuration.rb +9 -2
- data/lib/rails-settings/version.rb +1 -1
- data/rails-settings.gemspec +3 -3
- data/spec/configuration_spec.rb +12 -0
- data/spec/queries_spec.rb +1 -1
- data/spec/serialize_spec.rb +1 -1
- data/spec/setting_object_spec.rb +4 -4
- data/spec/settings_spec.rb +2 -2
- metadata +7 -11
- data/ci/Gemfile-rails-3-2 +0 -5
- data/ci/Gemfile-rails-4-0 +0 -6
- data/ci/Gemfile-rails-4-1 +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d35191c6b15823ec6934c9b66a8cf4291aa552c79bfe1ac6e24b2298a3bf6942
|
4
|
+
data.tar.gz: 1dabb6089d5894acc9f16aa57637daded9e9751c590b924fe3a8d3e074e01ac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2556adc7367efd4acd8a208d342d4f485ea356a79b1bac8971785bb2d3ab9ea3d31ec13b2008fe4e58171eb181090e7d7b18f3a242ee220fee9703777c7ca387
|
7
|
+
data.tar.gz: b391a6f0c86c8abab56b8b68b20161fbe4981c7d08acfa5766416d097d0c2ada7c77db29182b46b62853f0e822b77cc21ae300b3f42657c50cdebc7d83bdf4a8
|
data/.travis.yml
CHANGED
@@ -1,74 +1,17 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.2.9
|
7
|
-
- 2.3.6
|
8
|
-
- 2.4.3
|
9
|
-
- 2.5.0
|
3
|
+
- 2.4.6
|
4
|
+
- 2.5.5
|
5
|
+
- 2.6.3
|
10
6
|
gemfile:
|
11
|
-
- ci/Gemfile-rails-3-1
|
12
|
-
- ci/Gemfile-rails-3-2
|
13
|
-
- ci/Gemfile-rails-4-0
|
14
|
-
- ci/Gemfile-rails-4-1
|
15
7
|
- ci/Gemfile-rails-4-2
|
16
8
|
- ci/Gemfile-rails-5-0
|
17
9
|
- ci/Gemfile-rails-5-1
|
18
10
|
- ci/Gemfile-rails-5-2
|
11
|
+
- ci/Gemfile-rails-6-0
|
19
12
|
matrix:
|
20
|
-
include:
|
21
|
-
- rvm: 2.2.9
|
22
|
-
gemfile: ci/Gemfile-rails-4-0
|
23
|
-
env: PROTECTED_ATTRIBUTES=true
|
24
|
-
- rvm: 2.2.9
|
25
|
-
gemfile: ci/Gemfile-rails-4-1
|
26
|
-
env: PROTECTED_ATTRIBUTES=true
|
27
|
-
- rvm: 2.2.9
|
28
|
-
gemfile: ci/Gemfile-rails-4-2
|
29
|
-
env: PROTECTED_ATTRIBUTES=true
|
30
13
|
exclude:
|
31
|
-
- rvm:
|
32
|
-
gemfile: ci/Gemfile-rails-
|
33
|
-
- rvm: 1.9.3
|
34
|
-
gemfile: ci/Gemfile-rails-5-1
|
35
|
-
- rvm: 1.9.3
|
36
|
-
gemfile: ci/Gemfile-rails-5-2
|
37
|
-
- rvm: 2.0.0
|
38
|
-
gemfile: ci/Gemfile-rails-5-0
|
39
|
-
- rvm: 2.0.0
|
40
|
-
gemfile: ci/Gemfile-rails-5-1
|
41
|
-
- rvm: 2.0.0
|
42
|
-
gemfile: ci/Gemfile-rails-5-2
|
43
|
-
- rvm: 2.1.10
|
44
|
-
gemfile: ci/Gemfile-rails-5-0
|
45
|
-
- rvm: 2.1.10
|
46
|
-
gemfile: ci/Gemfile-rails-5-1
|
47
|
-
- rvm: 2.1.10
|
48
|
-
gemfile: ci/Gemfile-rails-5-2
|
49
|
-
- rvm: 2.2.9
|
50
|
-
gemfile: ci/Gemfile-rails-3-1
|
51
|
-
- rvm: 2.3.6
|
52
|
-
gemfile: ci/Gemfile-rails-3-1
|
53
|
-
- rvm: 2.4.3
|
54
|
-
gemfile: ci/Gemfile-rails-3-1
|
55
|
-
- rvm: 2.5.0
|
56
|
-
gemfile: ci/Gemfile-rails-3-1
|
57
|
-
- rvm: 2.2.9
|
58
|
-
gemfile: ci/Gemfile-rails-3-2
|
59
|
-
- rvm: 2.3.6
|
60
|
-
gemfile: ci/Gemfile-rails-3-2
|
61
|
-
- rvm: 2.4.3
|
62
|
-
gemfile: ci/Gemfile-rails-3-2
|
63
|
-
- rvm: 2.4.3
|
64
|
-
gemfile: ci/Gemfile-rails-4-0
|
65
|
-
- rvm: 2.4.3
|
66
|
-
gemfile: ci/Gemfile-rails-4-1
|
67
|
-
- rvm: 2.5.0
|
68
|
-
gemfile: ci/Gemfile-rails-3-2
|
69
|
-
- rvm: 2.5.0
|
70
|
-
gemfile: ci/Gemfile-rails-4-0
|
71
|
-
- rvm: 2.5.0
|
72
|
-
gemfile: ci/Gemfile-rails-4-1
|
14
|
+
- rvm: 2.4.6
|
15
|
+
gemfile: ci/Gemfile-rails-6-0
|
73
16
|
before_install: gem update bundler
|
74
17
|
sudo: false
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -8,8 +8,8 @@ Ruby gem to handle settings for ActiveRecord instances by storing them as serial
|
|
8
8
|
|
9
9
|
## Requirements
|
10
10
|
|
11
|
-
* Ruby
|
12
|
-
* Rails
|
11
|
+
* Ruby 2.4 or newer
|
12
|
+
* Rails 4.2 or newer (including Rails 6)
|
13
13
|
|
14
14
|
|
15
15
|
## Installation
|
@@ -65,6 +65,26 @@ class ProjectSettingObject < RailsSettings::SettingObject
|
|
65
65
|
end
|
66
66
|
```
|
67
67
|
|
68
|
+
In case you need to define settings separatedly for the same models, you can use the persistent option
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
module UserDashboardConcern
|
72
|
+
extend ActiveSupport::Concern
|
73
|
+
|
74
|
+
included do
|
75
|
+
has_settings persistent: true do |s|
|
76
|
+
s.key :dashboard
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class User < ActiveRecord::Base
|
82
|
+
has_settings persistent: true do |s|
|
83
|
+
s.key :calendar
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
68
88
|
### Set settings
|
69
89
|
|
70
90
|
```ruby
|
@@ -79,8 +99,8 @@ or
|
|
79
99
|
|
80
100
|
```ruby
|
81
101
|
user = User.find(1)
|
82
|
-
user.settings(:dashboard).
|
83
|
-
user.settings(:calendar).
|
102
|
+
user.settings(:dashboard).update! :theme => 'black'
|
103
|
+
user.settings(:calendar).update! :scope => 'all', :display => 'daily'
|
84
104
|
```
|
85
105
|
|
86
106
|
|
@@ -102,7 +122,7 @@ user.settings(:calendar).scope
|
|
102
122
|
|
103
123
|
```ruby
|
104
124
|
user = User.find(1)
|
105
|
-
user.settings(:dashboard).
|
125
|
+
user.settings(:dashboard).update! :theme => nil
|
106
126
|
|
107
127
|
user.settings(:dashboard).view = nil
|
108
128
|
user.settings(:dashboard).save!
|
@@ -118,7 +138,7 @@ User.without_settings
|
|
118
138
|
# => all users without having any setting
|
119
139
|
|
120
140
|
User.with_settings_for(:calendar)
|
121
|
-
# => all users having a setting for '
|
141
|
+
# => all users having a setting for 'calendar'
|
122
142
|
|
123
143
|
User.without_settings_for(:calendar)
|
124
144
|
# => all users without having settings for 'calendar'
|
@@ -146,6 +166,6 @@ See https://github.com/ledermann/rails-settings/releases
|
|
146
166
|
|
147
167
|
MIT License
|
148
168
|
|
149
|
-
Copyright (c) 2012-
|
169
|
+
Copyright (c) 2012-2019 [Georg Ledermann](http://www.georg-ledermann.de)
|
150
170
|
|
151
171
|
This gem is a complete rewrite of [rails-settings](https://github.com/Squeegy/rails-settings) by [Alex Wayne](https://github.com/Squeegy)
|
data/ci/Gemfile-rails-4-2
CHANGED
data/ci/Gemfile-rails-5-0
CHANGED
data/ci/Gemfile-rails-5-1
CHANGED
data/ci/Gemfile-rails-5-2
CHANGED
data/lib/rails-settings.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module RailsSettings
|
2
|
-
# In Rails 3, attributes can be protected by `attr_accessible` and `attr_protected`
|
3
2
|
# In Rails 4, attributes can be protected by using the gem `protected_attributes`
|
4
3
|
# In Rails 5, protecting attributes is obsolete (there are `StrongParameters` only)
|
5
4
|
def self.can_protect_attributes?
|
6
|
-
|
5
|
+
defined?(ProtectedAttributes)
|
7
6
|
end
|
8
7
|
end
|
9
8
|
|
@@ -20,4 +19,3 @@ ActiveRecord::Base.class_eval do
|
|
20
19
|
extend RailsSettings::Scopes
|
21
20
|
end
|
22
21
|
end
|
23
|
-
|
@@ -8,8 +8,15 @@ module RailsSettings
|
|
8
8
|
raise ArgumentError unless klass
|
9
9
|
|
10
10
|
@klass = klass
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
if options[:persistent]
|
13
|
+
@klass.class_attribute :default_settings unless @klass.methods.include?(:default_settings)
|
14
|
+
else
|
15
|
+
@klass.class_attribute :default_settings
|
16
|
+
end
|
17
|
+
|
18
|
+
@klass.class_attribute :setting_object_class_name
|
19
|
+
@klass.default_settings ||= {}
|
13
20
|
@klass.setting_object_class_name = options[:class_name] || 'RailsSettings::SettingObject'
|
14
21
|
|
15
22
|
if block_given?
|
data/rails-settings.gemspec
CHANGED
@@ -12,18 +12,18 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.description = %q{Settings gem for Ruby on Rails}
|
13
13
|
gem.summary = %q{Ruby gem to handle settings for ActiveRecord instances by storing them as serialized Hash in a separate database table. Namespaces and defaults included.}
|
14
14
|
gem.homepage = 'https://github.com/ledermann/rails-settings'
|
15
|
-
gem.required_ruby_version = '>=
|
15
|
+
gem.required_ruby_version = '>= 2.4'
|
16
16
|
|
17
17
|
gem.files = `git ls-files`.split($/)
|
18
18
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
20
|
gem.require_paths = ['lib']
|
21
21
|
|
22
|
-
gem.add_dependency 'activerecord', '>=
|
22
|
+
gem.add_dependency 'activerecord', '>= 4.2'
|
23
23
|
|
24
24
|
gem.add_development_dependency 'rake'
|
25
25
|
gem.add_development_dependency 'sqlite3'
|
26
26
|
gem.add_development_dependency 'rspec'
|
27
27
|
gem.add_development_dependency 'coveralls'
|
28
|
-
gem.add_development_dependency 'simplecov',
|
28
|
+
gem.add_development_dependency 'simplecov', '>= 0.11.2'
|
29
29
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -61,6 +61,18 @@ module RailsSettings
|
|
61
61
|
expect(Dummy.default_settings).to eq({ :dashboard => {}, :calendar => {} })
|
62
62
|
expect(Dummy.setting_object_class_name).to eq('MyClass')
|
63
63
|
end
|
64
|
+
|
65
|
+
context 'persistent' do
|
66
|
+
it "should keep settings between multiple configurations initialization" do
|
67
|
+
Configuration.new(Dummy, :persistent => true) do |c|
|
68
|
+
c.key :dashboard, :defaults => { :theme => 'red' }
|
69
|
+
end
|
70
|
+
|
71
|
+
Configuration.new(Dummy, :calendar, :persistent => true)
|
72
|
+
|
73
|
+
expect(Dummy.default_settings).to eq({ :dashboard => { 'theme' => 'red' }, :calendar => {} })
|
74
|
+
end
|
75
|
+
end
|
64
76
|
end
|
65
77
|
|
66
78
|
describe Configuration, 'failure' do
|
data/spec/queries_spec.rb
CHANGED
data/spec/serialize_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe "Serialization" do
|
|
25
25
|
|
26
26
|
describe 'updated settings' do
|
27
27
|
it 'should be serialized' do
|
28
|
-
user.settings(:dashboard).
|
28
|
+
user.settings(:dashboard).update! :smart => true
|
29
29
|
|
30
30
|
dashboard_settings = user.setting_objects.where(:var => 'dashboard').first
|
31
31
|
calendar_settings = user.setting_objects.where(:var => 'calendar').first
|
data/spec/setting_object_spec.rb
CHANGED
@@ -103,9 +103,9 @@ describe RailsSettings::SettingObject do
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
describe "
|
106
|
+
describe "update" do
|
107
107
|
it 'should save' do
|
108
|
-
expect(new_setting_object.
|
108
|
+
expect(new_setting_object.update(:foo => 42, :bar => 'string')).to be_truthy
|
109
109
|
new_setting_object.reload
|
110
110
|
|
111
111
|
expect(new_setting_object.foo).to eq(42)
|
@@ -115,12 +115,12 @@ describe RailsSettings::SettingObject do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'should not save blank hash' do
|
118
|
-
expect(new_setting_object.
|
118
|
+
expect(new_setting_object.update({})).to be_truthy
|
119
119
|
end
|
120
120
|
|
121
121
|
if RailsSettings.can_protect_attributes?
|
122
122
|
it 'should not allow changing protected attributes' do
|
123
|
-
new_setting_object.
|
123
|
+
new_setting_object.update!(:var => 'calendar', :foo => 42)
|
124
124
|
|
125
125
|
expect(new_setting_object.var).to eq('dashboard')
|
126
126
|
expect(new_setting_object.foo).to eq(42)
|
data/spec/settings_spec.rb
CHANGED
@@ -145,7 +145,7 @@ describe "Object without settings" do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
it "should add settings" do
|
148
|
-
user.settings(:dashboard).
|
148
|
+
user.settings(:dashboard).update! :smart => true
|
149
149
|
|
150
150
|
user.reload
|
151
151
|
expect(user.settings(:dashboard).smart).to eq(true)
|
@@ -179,7 +179,7 @@ describe "Object with settings" do
|
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should update settings" do
|
182
|
-
user.settings(:dashboard).
|
182
|
+
user.settings(:dashboard).update! :smart => true
|
183
183
|
user.reload
|
184
184
|
|
185
185
|
expect(user.settings(:dashboard).smart).to eq(true)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledermann-rails-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Ledermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,14 +107,11 @@ files:
|
|
107
107
|
- MIT-LICENSE
|
108
108
|
- README.md
|
109
109
|
- Rakefile
|
110
|
-
- ci/Gemfile-rails-3-1
|
111
|
-
- ci/Gemfile-rails-3-2
|
112
|
-
- ci/Gemfile-rails-4-0
|
113
|
-
- ci/Gemfile-rails-4-1
|
114
110
|
- ci/Gemfile-rails-4-2
|
115
111
|
- ci/Gemfile-rails-5-0
|
116
112
|
- ci/Gemfile-rails-5-1
|
117
113
|
- ci/Gemfile-rails-5-2
|
114
|
+
- ci/Gemfile-rails-6-0
|
118
115
|
- lib/generators/rails_settings/migration/migration_generator.rb
|
119
116
|
- lib/generators/rails_settings/migration/templates/migration.rb
|
120
117
|
- lib/ledermann-rails-settings.rb
|
@@ -147,15 +144,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
144
|
requirements:
|
148
145
|
- - ">="
|
149
146
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
147
|
+
version: '2.4'
|
151
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
149
|
requirements:
|
153
150
|
- - ">="
|
154
151
|
- !ruby/object:Gem::Version
|
155
152
|
version: '0'
|
156
153
|
requirements: []
|
157
|
-
|
158
|
-
rubygems_version: 2.7.5
|
154
|
+
rubygems_version: 3.0.6
|
159
155
|
signing_key:
|
160
156
|
specification_version: 4
|
161
157
|
summary: Ruby gem to handle settings for ActiveRecord instances by storing them as
|
data/ci/Gemfile-rails-3-2
DELETED
data/ci/Gemfile-rails-4-0
DELETED