ledermann-rails-settings 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +14 -11
- data/ci/Gemfile-rails-5-0 +1 -1
- data/lib/generators/rails_settings/migration/templates/migration.rb +7 -1
- data/lib/rails-settings.rb +9 -0
- data/lib/rails-settings/base.rb +1 -1
- data/lib/rails-settings/setting_object.rb +9 -5
- data/lib/rails-settings/version.rb +1 -1
- data/spec/setting_object_spec.rb +8 -2
- data/spec/spec_helper.rb +6 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1756804df911c376bd8148e110cc61cb6ddbccd
|
4
|
+
data.tar.gz: b60ca60dabb0980b32e4994e23657c50439aee15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfdb4f1e2290109d941d192585df3743b11daffa6ca2fbbf8dad83c94063e9a53db886341b5886f3fc917129dc9aa4ecad4661c8eb883773a2048594e2e03ff1
|
7
|
+
data.tar.gz: e0079aa1a2e667254c50dbeec82be481f41b024b28e0e2e11860303bd08f78205cb8e45b24abedca935b8521eef3cf91d48da9c9a6828ba0d7d73a455f6c3618
|
data/.travis.yml
CHANGED
@@ -2,9 +2,9 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
-
- 2.1.
|
6
|
-
- 2.2.
|
7
|
-
- 2.3.
|
5
|
+
- 2.1.10
|
6
|
+
- 2.2.5
|
7
|
+
- 2.3.1
|
8
8
|
gemfile:
|
9
9
|
- ci/Gemfile-rails-3-1
|
10
10
|
- ci/Gemfile-rails-3-2
|
@@ -14,10 +14,13 @@ gemfile:
|
|
14
14
|
- ci/Gemfile-rails-5-0
|
15
15
|
matrix:
|
16
16
|
include:
|
17
|
-
- rvm: 2.2.
|
18
|
-
gemfile: ci/Gemfile-rails-4-
|
17
|
+
- rvm: 2.2.5
|
18
|
+
gemfile: ci/Gemfile-rails-4-0
|
19
|
+
env: PROTECTED_ATTRIBUTES=true
|
20
|
+
- rvm: 2.2.5
|
21
|
+
gemfile: ci/Gemfile-rails-4-1
|
19
22
|
env: PROTECTED_ATTRIBUTES=true
|
20
|
-
- rvm: 2.
|
23
|
+
- rvm: 2.2.5
|
21
24
|
gemfile: ci/Gemfile-rails-4-2
|
22
25
|
env: PROTECTED_ATTRIBUTES=true
|
23
26
|
exclude:
|
@@ -25,15 +28,15 @@ matrix:
|
|
25
28
|
gemfile: ci/Gemfile-rails-5-0
|
26
29
|
- rvm: 2.0.0
|
27
30
|
gemfile: ci/Gemfile-rails-5-0
|
28
|
-
- rvm: 2.1.
|
31
|
+
- rvm: 2.1.10
|
29
32
|
gemfile: ci/Gemfile-rails-5-0
|
30
|
-
- rvm: 2.2.
|
33
|
+
- rvm: 2.2.5
|
31
34
|
gemfile: ci/Gemfile-rails-3-1
|
32
|
-
- rvm: 2.3.
|
35
|
+
- rvm: 2.3.1
|
33
36
|
gemfile: ci/Gemfile-rails-3-1
|
34
|
-
- rvm: 2.2.
|
37
|
+
- rvm: 2.2.5
|
35
38
|
gemfile: ci/Gemfile-rails-3-2
|
36
|
-
- rvm: 2.3.
|
39
|
+
- rvm: 2.3.1
|
37
40
|
gemfile: ci/Gemfile-rails-3-2
|
38
41
|
before_install: gem update bundler
|
39
42
|
sudo: false
|
data/ci/Gemfile-rails-5-0
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
MIGRATION_BASE_CLASS = if ActiveRecord::VERSION::MAJOR >= 5
|
2
|
+
ActiveRecord::Migration[5.0]
|
3
|
+
else
|
4
|
+
ActiveRecord::Migration
|
5
|
+
end
|
6
|
+
|
7
|
+
class RailsSettingsMigration < MIGRATION_BASE_CLASS
|
2
8
|
def self.up
|
3
9
|
create_table :settings do |t|
|
4
10
|
t.string :var, :null => false
|
data/lib/rails-settings.rb
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
module RailsSettings
|
2
|
+
# In Rails 3, attributes can be protected by `attr_accessible` and `attr_protected`
|
3
|
+
# In Rails 4, attributes can be protected by using the gem `protected_attributes`
|
4
|
+
# In Rails 5, protecting attributes is obsolete (there are `StrongParameters` only)
|
5
|
+
def self.can_protect_attributes?
|
6
|
+
(ActiveRecord::VERSION::MAJOR == 3) || defined?(ProtectedAttributes)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
1
10
|
require 'rails-settings/setting_object'
|
2
11
|
require 'rails-settings/configuration'
|
3
12
|
require 'rails-settings/base'
|
data/lib/rails-settings/base.rb
CHANGED
@@ -12,7 +12,7 @@ module RailsSettings
|
|
12
12
|
raise ArgumentError unless var.is_a?(Symbol)
|
13
13
|
raise ArgumentError.new("Unknown key: #{var}") unless self.class.default_settings[var]
|
14
14
|
|
15
|
-
if
|
15
|
+
if RailsSettings.can_protect_attributes?
|
16
16
|
setting_objects.detect { |s| s.var == var.to_s } || setting_objects.build({ :var => var.to_s }, :without_protection => true)
|
17
17
|
else
|
18
18
|
setting_objects.detect { |s| s.var == var.to_s } || setting_objects.build(:var => var.to_s, :target => self)
|
@@ -15,9 +15,9 @@ module RailsSettings
|
|
15
15
|
|
16
16
|
serialize :value, Hash
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
if RailsSettings.can_protect_attributes?
|
19
|
+
# attr_protected can not be used here because it touches the database which is not connected yet.
|
20
|
+
# So allow no attributes and override <tt>#sanitize_for_mass_assignment</tt>
|
21
21
|
attr_accessible
|
22
22
|
end
|
23
23
|
|
@@ -25,7 +25,7 @@ module RailsSettings
|
|
25
25
|
REGEX_GETTER = /\A([a-z]\w+)\Z/i
|
26
26
|
|
27
27
|
def respond_to?(method_name, include_priv=false)
|
28
|
-
super || method_name.to_s =~ REGEX_SETTER
|
28
|
+
super || method_name.to_s =~ REGEX_SETTER || _setting?(method_name)
|
29
29
|
end
|
30
30
|
|
31
31
|
def method_missing(method_name, *args, &block)
|
@@ -45,7 +45,7 @@ module RailsSettings
|
|
45
45
|
end
|
46
46
|
|
47
47
|
protected
|
48
|
-
if
|
48
|
+
if RailsSettings.can_protect_attributes?
|
49
49
|
# Simulate attr_protected by removing all regular attributes
|
50
50
|
def sanitize_for_mass_assignment(attributes, role = nil)
|
51
51
|
attributes.except('id', 'var', 'value', 'target_id', 'target_type', 'created_at', 'updated_at')
|
@@ -76,5 +76,9 @@ module RailsSettings
|
|
76
76
|
def _target_class
|
77
77
|
target_type.constantize
|
78
78
|
end
|
79
|
+
|
80
|
+
def _setting?(method_name)
|
81
|
+
_target_class.default_settings[var.to_sym].keys.include?(method_name.to_s)
|
82
|
+
end
|
79
83
|
end
|
80
84
|
end
|
data/spec/setting_object_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe RailsSettings::SettingObject do
|
4
4
|
let(:user) { User.create! :name => 'Mr. Pink' }
|
5
5
|
|
6
|
-
if
|
6
|
+
if RailsSettings.can_protect_attributes?
|
7
7
|
let(:new_setting_object) { user.setting_objects.build({ :var => 'dashboard'}, :without_protection => true) }
|
8
8
|
let(:saved_setting_object) { user.setting_objects.create!({ :var => 'dashboard', :value => { 'theme' => 'pink', 'filter' => false}}, :without_protection => true) }
|
9
9
|
else
|
@@ -52,6 +52,12 @@ describe RailsSettings::SettingObject do
|
|
52
52
|
expect(new_setting_object.filter).to eq(true)
|
53
53
|
end
|
54
54
|
|
55
|
+
it "should return defaults when using `try`" do
|
56
|
+
expect(new_setting_object.try(:theme)).to eq('blue')
|
57
|
+
expect(new_setting_object.try(:view)).to eq('monthly')
|
58
|
+
expect(new_setting_object.try(:filter)).to eq(true)
|
59
|
+
end
|
60
|
+
|
55
61
|
it "should store different objects to value hash" do
|
56
62
|
new_setting_object.integer = 42
|
57
63
|
new_setting_object.float = 1.234
|
@@ -112,7 +118,7 @@ describe RailsSettings::SettingObject do
|
|
112
118
|
expect(new_setting_object.update_attributes({})).to be_truthy
|
113
119
|
end
|
114
120
|
|
115
|
-
if
|
121
|
+
if RailsSettings.can_protect_attributes?
|
116
122
|
it 'should not allow changing protected attributes' do
|
117
123
|
new_setting_object.update_attributes!(:var => 'calendar', :foo => 42)
|
118
124
|
|
data/spec/spec_helper.rb
CHANGED
@@ -76,7 +76,12 @@ def setup_db
|
|
76
76
|
ActiveRecord::Base.configurations = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
|
77
77
|
ActiveRecord::Base.establish_connection(:sqlite)
|
78
78
|
ActiveRecord::Migration.verbose = false
|
79
|
-
|
79
|
+
|
80
|
+
print "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING}"
|
81
|
+
if ActiveRecord::VERSION::MAJOR == 4
|
82
|
+
print " #{defined?(ProtectedAttributes) ? 'with' : 'without'} gem `protected_attributes`"
|
83
|
+
end
|
84
|
+
puts
|
80
85
|
|
81
86
|
require File.expand_path('../../lib/generators/rails_settings/migration/templates/migration.rb', __FILE__)
|
82
87
|
RailsSettingsMigration.migrate(:up)
|
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.
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Ledermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
155
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.6.
|
156
|
+
rubygems_version: 2.6.6
|
157
157
|
signing_key:
|
158
158
|
specification_version: 4
|
159
159
|
summary: Ruby gem to handle settings for ActiveRecord instances by storing them as
|