attr_accessible_block 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.travis.yml +3 -3
- data/Gemfile +1 -1
- data/README.md +12 -11
- data/attr_accessible_block.gemspec +1 -1
- data/lib/attr_accessible_block.rb +12 -11
- data/lib/attr_accessible_block/version.rb +1 -1
- data/spec/attr_accessible_block_spec.rb +21 -2
- data/spec/spec_helper.rb +3 -0
- metadata +33 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8918b597936e811f939f5eca5a641518c12769d6
|
4
|
+
data.tar.gz: 22f12fa9cc3f02af96a74ad01bd2ecc67410d0b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c1ac574aa1202204436ef673eb2964d6e6e31ad62ffd325098c4c3971a1e0e3d4a85d3eed30380dfccb2a7b0c331c222e65055d76a7bf3fbca34d2835a4d90b
|
7
|
+
data.tar.gz: 91f3c4a7bd536c2f995d4c42f3e02f5390ab1d1a130f8351372a6d4ab97adb289b2ee1c588b127ba016928b7a6ffaabfc554d83418c002320e1b5ec66e0f2321
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service-name: travis-pro
|
data/.travis.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
rvm:
|
2
|
-
- 1.
|
3
|
-
-
|
4
|
-
- 1.
|
2
|
+
- 1.9.3
|
3
|
+
- 2.0.0
|
4
|
+
- 2.1.1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
AttrAccessibleBlock 0.3.
|
1
|
+
AttrAccessibleBlock 0.3.2
|
2
2
|
=========================
|
3
3
|
|
4
|
-
[![travis-ci status](https://secure.travis-ci.org/dmitry/attr_accessible_block.png)](http://travis-ci.org/dmitry/attr_accessible_block)
|
4
|
+
[![travis-ci status](https://secure.travis-ci.org/dmitry/attr_accessible_block.png)](http://travis-ci.org/dmitry/attr_accessible_block) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/dmitry/attr_accessible_block/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
5
5
|
|
6
|
-
|
6
|
+
Tested on Rubies: 1.9.2, 1.9.3, 2.0.0, thanks to Travis!
|
7
7
|
|
8
|
-
|
8
|
+
> If you need same functionallity for the Rails 2.3 or Rails 3.0, then use v0.2.2, it's fully tested and ready for this oldies. New version is total rewrite of the previous plugin, but API is the same, so it's easy to migrate if needed.
|
9
|
+
|
10
|
+
This is an ActiveModel plugin with possibility to define block inside the `attr_accessible` class method. `attr_protected` not supported.
|
9
11
|
|
10
12
|
Because of block, it's possible to define accessibles for instances, not just for the class level.
|
11
13
|
|
@@ -13,13 +15,12 @@ It's also still possible to define class level accessibles, so an old `attr_acce
|
|
13
15
|
|
14
16
|
Main features:
|
15
17
|
|
16
|
-
*
|
17
|
-
*
|
18
|
-
*
|
19
|
-
|
20
|
-
Also it's possible to check directly is attribute mass-assignable or no using `attr_accessible?` instance method.
|
18
|
+
* Add an accessible attributes based on current `record` state (eg. record.new_record?)
|
19
|
+
* Add additional variables and use it in the block (eg. current user) `ActiveModel::MassAssignmentSecurity::WhiteListBlock.add_variable(:user) { User.current || User.new }`
|
20
|
+
* Add permanently full accessibility on defined condition (eg.user.admin?) `ActiveModel::MassAssignmentSecurity::WhiteListBlock.always_accessible { user.admin? }`
|
21
|
+
* Check is attribute mass-assignable or no using `attr_accessible?` instance method, that returns boolean value.
|
21
22
|
|
22
|
-
See an examples to understand the conception.
|
23
|
+
See an examples to understand the conception or specs.
|
23
24
|
|
24
25
|
Installation
|
25
26
|
============
|
@@ -99,4 +100,4 @@ For more answers on your questions you can look into tests and source code.
|
|
99
100
|
|
100
101
|
Used on http://tenerife.by
|
101
102
|
|
102
|
-
Copyright (c) 2012 Dmitry Polushkin, released under the MIT license
|
103
|
+
Copyright (c) 2010-2012 Dmitry Polushkin, released under the MIT license
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = AttrAccessibleBlock::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency "activemodel", '
|
18
|
+
gem.add_dependency "activemodel", '~> 3.2'
|
19
19
|
gem.add_development_dependency "rspec"
|
20
20
|
gem.add_development_dependency "rake"
|
21
21
|
end
|
@@ -1,13 +1,12 @@
|
|
1
|
-
require "attr_accessible_block/version"
|
2
|
-
|
3
1
|
module ActiveModel::MassAssignmentSecurity
|
4
2
|
module ClassMethods
|
5
3
|
alias_method :old_attr_accessible, :attr_accessible
|
6
4
|
|
7
5
|
def attr_accessible(*attributes, &block)
|
8
|
-
class_attribute(:
|
6
|
+
class_attribute(:attr_accessible_blocks) unless respond_to?(:attr_accessible_blocks)
|
7
|
+
self.attr_accessible_blocks ||= []
|
9
8
|
|
10
|
-
self.
|
9
|
+
self.attr_accessible_blocks << (block_given? ? block : proc { add attributes })
|
11
10
|
|
12
11
|
include InstanceMethods
|
13
12
|
end
|
@@ -18,14 +17,14 @@ module ActiveModel::MassAssignmentSecurity
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def mass_assignment_authorizer
|
21
|
-
WhiteListBlock.new(
|
20
|
+
WhiteListBlock.new(self.class.attr_accessible_blocks)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
25
|
def attr_accessible?(attribute)
|
27
|
-
|
28
|
-
attributes = WhiteListBlock.new(
|
26
|
+
blocks = self.class.attr_accessible_blocks
|
27
|
+
attributes = WhiteListBlock.new(blocks).sanitize({attribute => send(attribute)}, self)
|
29
28
|
attributes.has_key?(attribute)
|
30
29
|
end
|
31
30
|
|
@@ -48,7 +47,9 @@ module ActiveModel::MassAssignmentSecurity
|
|
48
47
|
always_accessible = (@@always_accessible ? instance_eval(&@@always_accessible) : false)
|
49
48
|
|
50
49
|
unless always_accessible
|
51
|
-
|
50
|
+
@blocks.each do |block|
|
51
|
+
instance_eval(&block)
|
52
|
+
end
|
52
53
|
|
53
54
|
flatten!
|
54
55
|
reject_attributes!
|
@@ -57,8 +58,8 @@ module ActiveModel::MassAssignmentSecurity
|
|
57
58
|
@attributes
|
58
59
|
end
|
59
60
|
|
60
|
-
def initialize(
|
61
|
-
@
|
61
|
+
def initialize(blocks)
|
62
|
+
@blocks = blocks
|
62
63
|
super
|
63
64
|
end
|
64
65
|
|
@@ -81,4 +82,4 @@ module ActiveModel::MassAssignmentSecurity
|
|
81
82
|
@attributes.reject! { |k,v| !include?(k) }
|
82
83
|
end
|
83
84
|
end
|
84
|
-
end
|
85
|
+
end
|
@@ -25,8 +25,9 @@ class BaseModel
|
|
25
25
|
end
|
26
26
|
|
27
27
|
class User < BaseModel
|
28
|
-
attributes %w(email password date role)
|
28
|
+
attributes %w(name email password date role)
|
29
29
|
|
30
|
+
attr_accessible :name
|
30
31
|
attr_accessible :email, :password, :date
|
31
32
|
|
32
33
|
@@user = User.new
|
@@ -57,6 +58,24 @@ describe AttrAccessibleBlock do
|
|
57
58
|
user.role.should be_nil
|
58
59
|
end
|
59
60
|
|
61
|
+
it "should support concatenation of standard static attr_accessible" do
|
62
|
+
user = User.new(:name => "User Test", :email => 'test@test.com', :password => 'test', 'date(i0)' => '10', :role => 'admin')
|
63
|
+
user.name.should eq 'User Test'
|
64
|
+
user.password.should eq 'test'
|
65
|
+
user.email.should eq 'test@test.com'
|
66
|
+
user.date.should eq '10'
|
67
|
+
user.role.should be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should support #attr_accessible? with multiple attr_accessible" do
|
71
|
+
user = User.new(:name => "User Test", :email => 'test@test.com', :password => 'test', 'date(i0)' => '10', :role => 'admin')
|
72
|
+
user.attr_accessible?(:name).should be_true
|
73
|
+
user.attr_accessible?(:email).should be_true
|
74
|
+
user.attr_accessible?(:password).should be_true
|
75
|
+
user.attr_accessible?(:date).should be_true
|
76
|
+
user.attr_accessible?(:role).should be_false
|
77
|
+
end
|
78
|
+
|
60
79
|
it "should have standard static attr_accessible that always accessible" do
|
61
80
|
u = User.new.tap { |u| u.role = :admin }
|
62
81
|
User.should_receive(:current).twice.and_return(u)
|
@@ -102,4 +121,4 @@ describe AttrAccessibleBlock do
|
|
102
121
|
location.user.should eq 'user'
|
103
122
|
location.point.should be_nil
|
104
123
|
end
|
105
|
-
end
|
124
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,49 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_accessible_block
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Dmitry Polushkin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-06-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
prerelease: false
|
15
15
|
name: activemodel
|
16
|
-
requirement:
|
17
|
-
none: false
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
18
17
|
requirements:
|
19
|
-
- -
|
18
|
+
- - ~>
|
20
19
|
- !ruby/object:Gem::Version
|
21
|
-
version: '3.
|
20
|
+
version: '3.2'
|
22
21
|
type: :runtime
|
23
|
-
|
24
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
25
27
|
- !ruby/object:Gem::Dependency
|
28
|
+
prerelease: false
|
26
29
|
name: rspec
|
27
|
-
requirement:
|
28
|
-
none: false
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
29
31
|
requirements:
|
30
|
-
- -
|
32
|
+
- - '>='
|
31
33
|
- !ruby/object:Gem::Version
|
32
34
|
version: '0'
|
33
35
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
42
|
+
prerelease: false
|
37
43
|
name: rake
|
38
|
-
requirement:
|
39
|
-
none: false
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
40
45
|
requirements:
|
41
|
-
- -
|
46
|
+
- - '>='
|
42
47
|
- !ruby/object:Gem::Version
|
43
48
|
version: '0'
|
44
49
|
type: :development
|
45
|
-
|
46
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
description: Set attr_accessible attributes on runtime.
|
48
56
|
email:
|
49
57
|
- dmitry.polushkin@gmail.com
|
@@ -51,6 +59,7 @@ executables: []
|
|
51
59
|
extensions: []
|
52
60
|
extra_rdoc_files: []
|
53
61
|
files:
|
62
|
+
- .coveralls.yml
|
54
63
|
- .gitignore
|
55
64
|
- .rspec
|
56
65
|
- .travis.yml
|
@@ -66,27 +75,26 @@ files:
|
|
66
75
|
- spec/spec_helper.rb
|
67
76
|
homepage: https://github.com/dmitry/attr_accessible_block
|
68
77
|
licenses: []
|
78
|
+
metadata: {}
|
69
79
|
post_install_message:
|
70
80
|
rdoc_options: []
|
71
81
|
require_paths:
|
72
82
|
- lib
|
73
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
84
|
requirements:
|
76
|
-
- -
|
85
|
+
- - '>='
|
77
86
|
- !ruby/object:Gem::Version
|
78
87
|
version: '0'
|
79
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
89
|
requirements:
|
82
|
-
- -
|
90
|
+
- - '>='
|
83
91
|
- !ruby/object:Gem::Version
|
84
92
|
version: '0'
|
85
93
|
requirements: []
|
86
94
|
rubyforge_project:
|
87
|
-
rubygems_version:
|
95
|
+
rubygems_version: 2.2.2
|
88
96
|
signing_key:
|
89
|
-
specification_version:
|
97
|
+
specification_version: 4
|
90
98
|
summary: Bonus power attr_accessible on steroids with possibility to change accessibles
|
91
99
|
on the fly.
|
92
100
|
test_files: []
|