protector-simple_form 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +19 -0
- data/README.md +39 -0
- data/lib/protector/simple_form.rb +8 -0
- data/lib/protector/simple_form/form_builder.rb +31 -0
- data/lib/protector/simple_form/version.rb +5 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: abccaeb89148cc48d50f7b2d54b23a9360d13e5d
|
4
|
+
data.tar.gz: 84599928f6a1d5c0180694cdbb4195938e2731af
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f1bd10458b05d4bba3a0aa48be0f3b43468c26d31cb42c3b73ebe59e4a30cf6588e90f16294c0d9d57c86c570129c6ae1aef255733b16d63d2b7d396d529371
|
7
|
+
data.tar.gz: c6589e9847cee641358f93d19222ab248bc296f1adf8974dfbf9fe7fa961108c2b295bb6fa399d2609f8029a34e9b6f3c05268aa15ef00fd49ea7773ef4d0b06
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2013 Deversus Software Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
SimpleForm Protector
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Adds [Protector](https://github.com/inossidabile/protector) support to [SimpleForm](https://github.com/plataformatec/simple_form) associations.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "protector-simple_form"
|
12
|
+
```
|
13
|
+
|
14
|
+
And then run the following command to install it:
|
15
|
+
|
16
|
+
```console
|
17
|
+
bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Associations
|
23
|
+
|
24
|
+
SimpleForm does a great job at dealing with associations but when used in conjunction with Protector, it will not protect the collection used unless you specify it by hand using the `:collection` option.
|
25
|
+
|
26
|
+
This gem will protect the collections that are automatically generated by SimpleForm using the same subject as the object the association belongs to.
|
27
|
+
|
28
|
+
In the event where you'd rather not have the automatically generated collection protected, you can set the `:protect` option to `false`.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
<%= simple_form_for @user do |f| %>
|
32
|
+
<%= f.association :company, protect: false %>
|
33
|
+
<%= f.association :roles %>
|
34
|
+
<% end %>
|
35
|
+
```
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
Copyright 2013 [Deversus Software Inc](http://www.deversus.com). It is free software, and may be redistributed under the terms of MIT license.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Protector
|
2
|
+
module SimpleForm
|
3
|
+
module FormBuilder
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
alias_method :association_without_monkey_patch, :association
|
8
|
+
def association(association, options={}, &block)
|
9
|
+
options = options.dup
|
10
|
+
|
11
|
+
# Always protect unless otherwise specified.
|
12
|
+
options[:protect] = true unless options[:protect] == false
|
13
|
+
|
14
|
+
if options[:protect] == true && @object.respond_to?(:protector_subject?) && @object.protector_subject?
|
15
|
+
return simple_fields_for(*[association, options.delete(:collection), options].compact, &block) if block_given?
|
16
|
+
|
17
|
+
reflection = find_association_reflection(association)
|
18
|
+
raise "Association #{association.inspect} not found" unless reflection
|
19
|
+
|
20
|
+
options[:collection] ||= options.fetch(:collection) do
|
21
|
+
# Protect using the same subject as the the current object.
|
22
|
+
reflection.klass.restrict!(@object.protector_subject).where(reflection.options[:conditions]).order(reflection.options[:order]).to_a
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
association_without_monkey_patch association, options, &block
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: protector-simple_form
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francois Deschenes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: simple_form
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: protector
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Adds Protector support to SimpleForm associations.
|
70
|
+
email:
|
71
|
+
- fdeschenes@me.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- lib/protector/simple_form/form_builder.rb
|
79
|
+
- lib/protector/simple_form/version.rb
|
80
|
+
- lib/protector/simple_form.rb
|
81
|
+
homepage: https://github.com/deversus/protector-simple_form
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.0.0
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: SimpleForm Protector
|
105
|
+
test_files: []
|