let_me_mass_assign_protected_attributes 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -1,3 +1,30 @@
1
+ Deprecated as of Rails 3.2
2
+ ==========================
3
+
4
+ This library is, happily, no longer useful now that Rails 3.2 has introduced the `without_protection: true` option!
5
+
6
+ So instead of
7
+
8
+ user = User.unprotected_new(
9
+ name: 'Some Name',
10
+ email: 'test@example.com',
11
+ ...
12
+ is_admin: true,
13
+ state: :active
14
+ )
15
+
16
+ you can now do this in Rails 3.2+:
17
+
18
+ user = User.new({
19
+ name: 'Some Name',
20
+ email: 'test@example.com',
21
+ ...
22
+ is_admin: true,
23
+ state: :active
24
+ }, without_protection: true)
25
+
26
+ Please use that built-in feature instead. This library will no longer be maintained.
27
+
1
28
  Let me mass-assign protected attributes!
2
29
  ========================================
3
30
 
@@ -4,7 +4,7 @@ require "let_me_mass_assign_protected_attributes/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "let_me_mass_assign_protected_attributes"
7
- s.version = LetMeMassAssignProtectedAttributes::Version
7
+ s.version = LetMeMassAssignProtectedAttributes.version
8
8
  s.authors = ["Tyler Rick"]
9
9
  s.email = ["tyler@tylerrick.com"]
10
10
  s.homepage = ""
@@ -4,54 +4,32 @@ module LetMeMassAssignProtectedAttributes
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  def unprotected_attributes=(attributes)
7
- self.tap do
8
- attributes.each do |key, value|
9
- self.send "#{key}=", value
10
- end
11
- end
7
+ assign_attributes(attributes, without_protection: true)
12
8
  end
13
9
 
14
10
  # update_attributes doesn't set attributes protected via attr_protected (instead, it logs a warning informing you that you are trying to mass-assign protected attributes), so this method is convenient if you have a hash of protected attributes that you want to set
15
11
  def unprotected_update_attributes(attributes)
16
- self.tap do
17
- self.unprotected_attributes = attributes
18
- save
19
- end
12
+ update_attributes(attributes, without_protection: true)
20
13
  end
21
14
 
22
15
  # Updates an object just like Base.unprotected_update_attributes but calls save! instead of save so an exception is raised if the record is invalid.
23
16
  def unprotected_update_attributes!(attributes)
24
- self.tap do
25
- self.unprotected_attributes = attributes
26
- save!
27
- end
17
+ update_attributes!(attributes, without_protection: true)
28
18
  end
29
19
 
30
20
  module ClassMethods
31
21
  # The same as a normal new, only it lets you initialize/set attr_protected attributes
32
22
  def unprotected_new(attributes = {})
33
- if attributes.is_a?(Array)
34
- attributes.each {|attributes| unprotected_new(attributes) }
35
- else
36
- new.tap {|_| _.unprotected_attributes = attributes }
37
- end
23
+ new(attributes, without_protection: true)
38
24
  end
39
25
 
40
26
  # The same as a normal create, only it lets you initialize/set attr_protected attributes
41
27
  def unprotected_create(attributes = {})
42
- if attributes.is_a?(Array)
43
- attributes.each {|attributes| unprotected_create(attributes) }
44
- else
45
- new.unprotected_update_attributes(attributes)
46
- end
28
+ create(attributes, without_protection: true)
47
29
  end
48
30
 
49
31
  def unprotected_create!(attributes = {})
50
- if attributes.is_a?(Array)
51
- attributes.each {|attributes| unprotected_create!(attributes) }
52
- else
53
- new.unprotected_update_attributes!(attributes)
54
- end
32
+ create!(attributes, without_protection: true)
55
33
  end
56
34
  end
57
35
  end
@@ -1,3 +1,5 @@
1
1
  module LetMeMassAssignProtectedAttributes
2
- Version = "0.0.2"
2
+ def self.version
3
+ "0.0.3"
4
+ end
3
5
  end
metadata CHANGED
@@ -1,29 +1,25 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: let_me_mass_assign_protected_attributes
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
4
5
  prerelease:
5
- version: 0.0.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Tyler Rick
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-09-13 00:00:00 -07:00
14
- default_executable:
12
+ date: 2012-11-30 00:00:00.000000000 Z
15
13
  dependencies: []
16
-
17
- description: Thank you, Active Record, for not letting me mass-assign protected attributes. But sometimes I want to anyway. This gem provides unprotected_update_attributes, unprotected_create, and related methods to ActiveRecord::Base.
18
- email:
14
+ description: Thank you, Active Record, for not letting me mass-assign protected attributes.
15
+ But sometimes I want to anyway. This gem provides unprotected_update_attributes,
16
+ unprotected_create, and related methods to ActiveRecord::Base.
17
+ email:
19
18
  - tyler@tylerrick.com
20
19
  executables: []
21
-
22
20
  extensions: []
23
-
24
21
  extra_rdoc_files: []
25
-
26
- files:
22
+ files:
27
23
  - .gitignore
28
24
  - Gemfile
29
25
  - Rakefile
@@ -31,33 +27,31 @@ files:
31
27
  - let_me_mass_assign_protected_attributes.gemspec
32
28
  - lib/let_me_mass_assign_protected_attributes.rb
33
29
  - lib/let_me_mass_assign_protected_attributes/version.rb
34
- has_rdoc: true
35
- homepage: ""
30
+ homepage: ''
36
31
  licenses: []
37
-
38
32
  post_install_message:
39
33
  rdoc_options: []
40
-
41
- require_paths:
34
+ require_paths:
42
35
  - lib
43
- required_ruby_version: !ruby/object:Gem::Requirement
36
+ required_ruby_version: !ruby/object:Gem::Requirement
44
37
  none: false
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: "0"
49
- required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
43
  none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: "0"
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
55
48
  requirements: []
56
-
57
49
  rubyforge_project:
58
- rubygems_version: 1.5.2
50
+ rubygems_version: 1.8.15
59
51
  signing_key:
60
52
  specification_version: 3
61
- summary: Thank you, Active Record, for not letting me mass-assign protected attributes. But sometimes I want to anyway. This gem provides unprotected_update_attributes, unprotected_create, and related methods to ActiveRecord::Base.
53
+ summary: Thank you, Active Record, for not letting me mass-assign protected attributes.
54
+ But sometimes I want to anyway. This gem provides unprotected_update_attributes,
55
+ unprotected_create, and related methods to ActiveRecord::Base.
62
56
  test_files: []
63
-
57
+ has_rdoc: