attribute-permissions 0.9

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.
Files changed (4) hide show
  1. data/LICENSE +20 -0
  2. data/README +21 -0
  3. data/lib/mass_assignment.rb +52 -0
  4. metadata +69 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) Fingertips, Manfred Stienstra <manfred@fngtps.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,21 @@
1
+ = Attribute permissions
2
+
3
+ Adds a class and instance method to ActiveRecord::Base that enables you to mass assign attributes circumventing the attribute protection. It can be used in admin actions that don't want to be limited by attr_protected or attr_accessible when assigning attributes.
4
+
5
+ == Example
6
+
7
+ class User < ActiveRecord::Base
8
+ attr_accessible :full_name
9
+ end
10
+
11
+ # Initialize a new User
12
+ user = User.mass_assign(params[:user])
13
+ user.save
14
+
15
+ # Update a user
16
+ user.mass_assign(param[:user])
17
+ user.save
18
+
19
+ == Install
20
+
21
+ $ gem install attribute-permissions
@@ -0,0 +1,52 @@
1
+ # Implements the mass_assign instance and class methods. Include in your class for easy mass assignments.
2
+ #
3
+ # class Book
4
+ # attr_accessor :title, :author
5
+ # include MassAssignment
6
+ # end
7
+ #
8
+ # book = Book.mass_assign(:title => 'The Little Red Book', :author => 'Jenny from the Block')
9
+ # book.title #=> 'The Little Red Book'
10
+ module MassAssignment
11
+ def self.included(klass)
12
+ klass.extend ClassMethods
13
+ end
14
+
15
+ module ClassMethods
16
+ # Intializes a new object and assigns the attribute hash to the appropriate
17
+ # attribute writers using the mass_assign method on the newly created object.
18
+ #
19
+ # Example:
20
+ #
21
+ # User.mass_assign(:username => 'Manfred', :password => 'very secret')
22
+ #
23
+ # Instead of:
24
+ #
25
+ # user = User.new
26
+ # user.mass_assign(:username => 'Manfred', :password => 'very secret')
27
+ def mass_assign(attributes)
28
+ object = new
29
+ object.mass_assign(attributes)
30
+ object
31
+ end
32
+ end
33
+
34
+ # Sends all the attributes in the attribute hash to the appropriate attribute writer.
35
+ # This is a way to circumvent the normal attribute protection on Rails models.
36
+ #
37
+ # Example:
38
+ #
39
+ # user.mass_assign(:username => 'Manfred', :password => 'very secret')
40
+ #
41
+ # Instead of:
42
+ #
43
+ # user.username = 'Manfred'
44
+ # user.password = 'very secret'
45
+ def mass_assign(attributes)
46
+ send(:attributes=, attributes, false)
47
+ end
48
+ end
49
+
50
+ class ActiveRecord::Base
51
+ include MassAssignment
52
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: attribute-permissions
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ version: "0.9"
10
+ platform: ruby
11
+ authors:
12
+ - Manfred Stienstra
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-15 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: " A plugin to manage attribute permissions on ActiveRecord more effectively \n"
22
+ email: manfred@fngtps.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README
29
+ - LICENSE
30
+ files:
31
+ - lib/mass_assignment.rb
32
+ - README
33
+ - LICENSE
34
+ has_rdoc: true
35
+ homepage:
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=utf-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 3
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.5.2
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Attribute Permissions adds methods to mass-assign attributes to ActiveRecord objects. It enables you to circumvent attribute protection with a minimal amount of code.
68
+ test_files: []
69
+