ledermann-rails-settings 2.0.3 → 2.1.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 +1 -1
- data/Changelog.md +6 -0
- data/README.md +3 -3
- data/ci/Gemfile.rails-4.0.x +7 -0
- data/lib/rails-settings/base.rb +5 -1
- data/lib/rails-settings/setting_object.rb +21 -8
- data/lib/rails-settings/version.rb +1 -1
- data/rails-settings.gemspec +5 -5
- data/spec/setting_object_spec.rb +14 -6
- metadata +22 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be934fefff4c87ca3858e881e4c094e256af5381
|
4
|
+
data.tar.gz: f13141fd1154045b71a0bd332288309a916ceba9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8b17fd4dd288c307233a26f1ae2c29aee029fc77fee738545c59e3f1fc6906a182786d737b894d89581d774ed62274db7b55f24ec6f21b828116b31e79a04d6
|
7
|
+
data.tar.gz: 171041cbb7fb74001ac6bfb756bb3819fbd31a03adfc1696998afb4f6194d849ea547077a4c59779dea04225833f08e69a2f1cad19bf63e218ca698a5aab76fa
|
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Settings for Rails
|
1
|
+
# Settings for Rails
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/ledermann/rails-settings.png?branch=master)](https://travis-ci.org/ledermann/rails-settings)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/ledermann/rails-settings.png)](https://codeclimate.com/github/ledermann/rails-settings)
|
@@ -96,8 +96,8 @@ User.without_settings_for(:calendar)
|
|
96
96
|
|
97
97
|
## Requirements
|
98
98
|
|
99
|
-
* Ruby 1.
|
100
|
-
* Rails 3.1
|
99
|
+
* Ruby 1.9.3 or 2.0.0
|
100
|
+
* Rails 3.1 or greater (including Rails 4)
|
101
101
|
|
102
102
|
|
103
103
|
## Installation
|
data/lib/rails-settings/base.rb
CHANGED
@@ -12,7 +12,11 @@ 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
|
-
|
15
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
16
|
+
setting_objects.detect { |s| s.var == var.to_s } || setting_objects.build({ :var => var.to_s }, :without_protection => true)
|
17
|
+
else
|
18
|
+
setting_objects.detect { |s| s.var == var.to_s } || setting_objects.build(:var => var.to_s, :target => self)
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
def settings=(value)
|
@@ -15,7 +15,9 @@ module RailsSettings
|
|
15
15
|
|
16
16
|
# attr_protected can not be here used because it touches the database which is not connected yet.
|
17
17
|
# So allow no attributes and override <tt>#sanitize_for_mass_assignment</tt>
|
18
|
-
|
18
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
19
|
+
attr_accessible
|
20
|
+
end
|
19
21
|
|
20
22
|
REGEX_SETTER = /\A([a-z]\w+)=\Z/i
|
21
23
|
REGEX_GETTER = /\A([a-z]\w+)\Z/i
|
@@ -28,7 +30,9 @@ module RailsSettings
|
|
28
30
|
if block_given?
|
29
31
|
super
|
30
32
|
else
|
31
|
-
if method_name.to_s
|
33
|
+
if attribute_names.include?(method_name.to_s.sub('=',''))
|
34
|
+
super
|
35
|
+
elsif method_name.to_s =~ REGEX_SETTER && args.size == 1
|
32
36
|
_set_value($1, args.first)
|
33
37
|
elsif method_name.to_s =~ REGEX_GETTER && args.size == 0
|
34
38
|
_get_value($1)
|
@@ -39,9 +43,11 @@ module RailsSettings
|
|
39
43
|
end
|
40
44
|
|
41
45
|
protected
|
42
|
-
|
43
|
-
|
44
|
-
attributes
|
46
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
47
|
+
# Simulate attr_protected by removing all regular attributes
|
48
|
+
def sanitize_for_mass_assignment(attributes, role = nil)
|
49
|
+
attributes.except('id', 'var', 'value', 'target_id', 'target_type', 'created_at', 'updated_at')
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
53
|
private
|
@@ -69,10 +75,17 @@ module RailsSettings
|
|
69
75
|
target_type.constantize
|
70
76
|
end
|
71
77
|
|
72
|
-
|
73
|
-
|
78
|
+
# Patch ActiveRecord to save serialized attributes only if they are changed
|
79
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
74
80
|
# https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/attribute_methods/dirty.rb#L70
|
75
|
-
|
81
|
+
def update(*)
|
82
|
+
super(changed) if changed?
|
83
|
+
end
|
84
|
+
else
|
85
|
+
# https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/attribute_methods/dirty.rb#L73
|
86
|
+
def update_record(*)
|
87
|
+
super(keys_for_partial_write) if changed?
|
88
|
+
end
|
76
89
|
end
|
77
90
|
end
|
78
91
|
end
|
data/rails-settings.gemspec
CHANGED
@@ -17,10 +17,10 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ['lib']
|
19
19
|
|
20
|
-
gem.add_dependency 'activerecord', '
|
20
|
+
gem.add_dependency 'activerecord', '>= 3.1'
|
21
21
|
|
22
|
-
gem.add_development_dependency 'rake'
|
23
|
-
gem.add_development_dependency 'sqlite3'
|
24
|
-
gem.add_development_dependency 'mysql2'
|
25
|
-
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
gem.add_development_dependency 'sqlite3'
|
24
|
+
gem.add_development_dependency 'mysql2'
|
25
|
+
gem.add_development_dependency 'rspec'
|
26
26
|
end
|
data/spec/setting_object_spec.rb
CHANGED
@@ -2,8 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe RailsSettings::SettingObject do
|
4
4
|
let(:user) { User.create! :name => 'Mr. Pink' }
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
7
|
+
let(:new_setting_object) { user.setting_objects.build({ :var => 'dashboard'}, :without_protection => true) }
|
8
|
+
let(:saved_setting_object) { user.setting_objects.create!({ :var => 'dashboard', :value => { 'theme' => 'pink', 'filter' => false}}, :without_protection => true) }
|
9
|
+
else
|
10
|
+
let(:new_setting_object) { user.setting_objects.build({ :var => 'dashboard'}) }
|
11
|
+
let(:saved_setting_object) { user.setting_objects.create!({ :var => 'dashboard', :value => { 'theme' => 'pink', 'filter' => false}}) }
|
12
|
+
end
|
7
13
|
|
8
14
|
describe "serialization" do
|
9
15
|
it "should have a hash default" do
|
@@ -106,11 +112,13 @@ describe RailsSettings::SettingObject do
|
|
106
112
|
new_setting_object.update_attributes({}).should be_false
|
107
113
|
end
|
108
114
|
|
109
|
-
|
110
|
-
|
115
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
116
|
+
it 'should not allow changing protected attributes' do
|
117
|
+
new_setting_object.update_attributes!(:var => 'calendar', :foo => 42)
|
111
118
|
|
112
|
-
|
113
|
-
|
119
|
+
new_setting_object.var.should eq('dashboard')
|
120
|
+
new_setting_object.foo.should eq(42)
|
121
|
+
end
|
114
122
|
end
|
115
123
|
end
|
116
124
|
|
metadata
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledermann-rails-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.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: 2013-
|
11
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.1'
|
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
26
|
version: '3.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sqlite3
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mysql2
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
description: Settings gem for Ruby on Rails
|
84
84
|
email:
|
85
85
|
- mail@georg-ledermann.de
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- Rakefile
|
97
97
|
- ci/Gemfile.rails-3.1.x
|
98
98
|
- ci/Gemfile.rails-3.2.x
|
99
|
+
- ci/Gemfile.rails-4.0.x
|
99
100
|
- lib/generators/rails_settings/migration/migration_generator.rb
|
100
101
|
- lib/generators/rails_settings/migration/templates/migration.rb
|
101
102
|
- lib/rails-settings.rb
|
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
version: '0'
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.1.3
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: Ruby gem to handle settings for ActiveRecord instances by storing them as
|