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.
@@ -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
@@ -0,0 +1 @@
1
+ service-name: travis-pro
@@ -1,4 +1,4 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.2
4
- - 1.9.3
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.1
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in attr_accessible_block.gemspec
4
3
  gemspec
5
4
 
5
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
- AttrAccessibleBlock 0.3.1
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
- > 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.
6
+ Tested on Rubies: 1.9.2, 1.9.3, 2.0.0, thanks to Travis!
7
7
 
8
- This is an ActiveModel plugin with possibility to define block inside the `attr_accessible` class method.
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
- * Possibility to add an accessible attributes based on current `record` state (eg. record.new_record?)
17
- * Possibility to add additional variables and use it in the block (eg. user.role) `ActiveRecord::AttrAccessibleBlock.add_variable(:user) { User.current || User.new }`
18
- * Possibility to add permanently total accessibility in defined condition (eg.user.admin?) `ActiveRecord::AttrAccessibleBlock.always_accessible { user.admin? }`
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", '>= 3.1'
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(:attr_accessible_block)
6
+ class_attribute(:attr_accessible_blocks) unless respond_to?(:attr_accessible_blocks)
7
+ self.attr_accessible_blocks ||= []
9
8
 
10
- self.attr_accessible_block = (block_given? ? block : proc { add attributes })
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(&self.class.attr_accessible_block)
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
- block = self.class.attr_accessible_block
28
- attributes = WhiteListBlock.new(&block).sanitize({attribute => send(attribute)}, self)
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
- instance_eval(&@block)
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(&block)
61
- @block = block
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
@@ -1,3 +1,3 @@
1
1
  module AttrAccessibleBlock
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  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
@@ -1,2 +1,5 @@
1
1
  require 'active_model'
2
2
  require 'attr_accessible_block'
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
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.1
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: 2011-12-24 00:00:00.000000000 Z
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: &8837640 !ruby/object:Gem::Requirement
17
- none: false
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  requirements:
19
- - - ! '>='
18
+ - - ~>
20
19
  - !ruby/object:Gem::Version
21
- version: '3.1'
20
+ version: '3.2'
22
21
  type: :runtime
23
- prerelease: false
24
- version_requirements: *8837640
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: &8836740 !ruby/object:Gem::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
- prerelease: false
35
- version_requirements: *8836740
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: &8834580 !ruby/object:Gem::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
- prerelease: false
46
- version_requirements: *8834580
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: 1.8.10
95
+ rubygems_version: 2.2.2
88
96
  signing_key:
89
- specification_version: 3
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: []