guachiman 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa52dd4ec1065cbe50089e4adb05fd695e8fce11
4
- data.tar.gz: d4cb823cee82b07561940986cc2c5beb1f29d142
3
+ metadata.gz: 8e800c68b0ed65758b2d1c4f48e37ed9934c3e19
4
+ data.tar.gz: dde75fbbbc432e64e3454b138358f93c20aa24f4
5
5
  SHA512:
6
- metadata.gz: 27f1a056431c28ff23a2b01846f5c9a3a19fb8b0f1d7e4b94409a96ba1b19dd4396cfca83196d6e9e34ae9f955a3b917f164aeecab34cdb255aaef3ac25f9425
7
- data.tar.gz: f914875964ce20b71eb1ab8074276c6f225dd70d830a1263322cca152ac20894d57852656f5793e019f41db85b2dd0e379fc59856eb118b02c0580dac0d015b6
6
+ metadata.gz: 8a4ac42c31cd4fb7148fe705165118f78e2f69fa151811b699866242d9ac93e19929ea0aa2eaa0db2cec9e75bc76f39734d03d6317c52e22ef919cf239371d72
7
+ data.tar.gz: 2dc35a2574b6e7cf82d12b5ed9ceb051c771a97b34d4397d7f0fb2a9662dc2f2da229fb2463be1207ed37839d75e2c79279639cea72ec0e0e59dbc918580bbc0
@@ -1,5 +1,6 @@
1
1
  require 'guachiman/version'
2
2
  require 'guachiman/permissions'
3
+ require 'guachiman/strong_parameters'
3
4
  require 'guachiman/params'
4
5
 
5
6
  if defined? Rails
@@ -3,7 +3,7 @@ module Guachiman
3
3
  attr_reader :allowed_actions, :allow_all
4
4
 
5
5
  def allow controllers, actions, &block
6
- @allowed_actions ||= Hash.new
6
+ @allowed_actions ||= {}
7
7
  Array(controllers).each do |controller|
8
8
  Array(actions).each do |action|
9
9
  allowed_actions[controller] ||= {}
@@ -0,0 +1,33 @@
1
+ module Guachiman
2
+ module StrongParameters
3
+ attr_reader :allowed_params
4
+
5
+ def allow_param resources, attributes
6
+ @allowed_params ||= {}
7
+ Array(resources).each do |resource|
8
+ allowed_params[resource] ||= []
9
+ allowed_params[resource] += Array(attributes)
10
+ end
11
+ end
12
+
13
+ def allow_param?(resource, attribute)
14
+ if @allow_all
15
+ true
16
+ elsif @allowed_params && @allowed_params[resource]
17
+ @allowed_params[resource].include? attribute
18
+ end
19
+ end
20
+
21
+ def permit_params! params
22
+ if @allow_all
23
+ params.permit!
24
+ elsif allowed_params
25
+ allowed_params.each do |resource, attributes|
26
+ if params[resource].respond_to? :permit
27
+ params[resource] = params[resource].permit(*attributes)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module Guachiman
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guachiman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Rodriguez
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-08 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -102,6 +102,7 @@ files:
102
102
  - lib/guachiman/permissions.rb
103
103
  - lib/guachiman/rails/permissible.rb
104
104
  - lib/guachiman/rails/railtie.rb
105
+ - lib/guachiman/strong_parameters.rb
105
106
  - lib/guachiman/version.rb
106
107
  - test/generators/install_generator_test.rb
107
108
  - test/test_helper.rb