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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ff4a6ba546d2daf89db23836a41e7a4e387afe8
4
- data.tar.gz: 1131ffb90652265e634619fe33aa41c492d1b80b
3
+ metadata.gz: be934fefff4c87ca3858e881e4c094e256af5381
4
+ data.tar.gz: f13141fd1154045b71a0bd332288309a916ceba9
5
5
  SHA512:
6
- metadata.gz: 5713e46631870b7f3f9e6df62893bc1ca6fa43d07f3c4f4dee3100a2c0abed752e68f21b284003a462937ba92704afd8a99651198f16b5d567cb4a8882c0a631
7
- data.tar.gz: 8f714acf90e0db2ad9e0786f734c6d87983d4b7af8153e94b368e10185fdf18f85f7db3ccde672b454094184d96999fafebc515cde71b0237c517c7996f43857
6
+ metadata.gz: b8b17fd4dd288c307233a26f1ae2c29aee029fc77fee738545c59e3f1fc6906a182786d737b894d89581d774ed62274db7b55f24ec6f21b828116b31e79a04d6
7
+ data.tar.gz: 171041cbb7fb74001ac6bfb756bb3819fbd31a03adfc1696998afb4f6194d849ea547077a4c59779dea04225833f08e69a2f1cad19bf63e218ca698a5aab76fa
data/.travis.yml CHANGED
@@ -1,11 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.3
5
4
  - 2.0.0
6
5
  gemfile:
7
6
  - ci/Gemfile.rails-3.1.x
8
7
  - ci/Gemfile.rails-3.2.x
8
+ - ci/Gemfile.rails-4.0.x
9
9
  env:
10
10
  - DB=sqlite
11
11
  - DB=mysql
data/Changelog.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 2.1.0 (2013-09-13)
4
+
5
+ - Support for Rails 4
6
+ - Removed support for Ruby 1.8.7
7
+
8
+
3
9
  ## Version 2.0.3 (2013-04-16)
4
10
 
5
11
  - Fixed bug with setting getter when settings are booleans and default is true (thanks to @mduong)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Settings for Rails 3
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.8.7, 1.9.3 or 2.0.0
100
- * Rails 3.1.x or 3.2.x
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
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'activerecord', '~> 4.0.0'
4
+ gem 'sqlite3', '~> 1.3'
5
+ gem 'mysql2', '>= 0.3.6'
6
+ gem 'rake', '~> 10.0'
7
+ gem 'rspec', '~> 2.13'
@@ -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
- setting_objects.detect { |s| s.var == var.to_s } || setting_objects.build({ :var => var.to_s }, :without_protection => true)
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
- attr_accessible
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 =~ REGEX_SETTER && args.size == 1
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
- # Simulate attr_protected by removing all regular attributes
43
- def sanitize_for_mass_assignment(attributes, role = nil)
44
- attributes.except('id', 'var', 'value', 'target_id', 'target_type', 'created_at', 'updated_at')
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
- def update(*)
73
- # Patch ActiveRecord to save serialized attributes only if they are changed
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
- super(changed) if changed?
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
@@ -1,3 +1,3 @@
1
1
  module RailsSettings
2
- VERSION = '2.0.3'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -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', '~> 3.1'
20
+ gem.add_dependency 'activerecord', '>= 3.1'
21
21
 
22
- gem.add_development_dependency 'rake', '~> 10.0'
23
- gem.add_development_dependency 'sqlite3', '~> 1.3'
24
- gem.add_development_dependency 'mysql2', '~> 0.3.11'
25
- gem.add_development_dependency 'rspec', '~> 2.13'
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
@@ -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
- let(:new_setting_object) { user.setting_objects.build({ :var => 'dashboard'}, :without_protection => true) }
6
- let(:saved_setting_object) { user.setting_objects.create!({ :var => 'dashboard', :value => { 'theme' => 'pink', 'filter' => false}}, :without_protection => true) }
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
- it 'should not allow changing protected attributes' do
110
- new_setting_object.update_attributes!(:var => 'calendar', :foo => 42)
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
- new_setting_object.var.should eq('dashboard')
113
- new_setting_object.foo.should eq(42)
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.3
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-04-16 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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: '1.3'
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: '1.3'
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.3.11
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.3.11
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: '2.13'
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: '2.13'
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.0.3
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