Class: ParamAccessible::Rule
- Inherits:
-
Object
- Object
- ParamAccessible::Rule
- Defined in:
- lib/param_accessible/rule.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#except_options ⇒ Object
readonly
Returns the value of attribute except_options.
-
#if_option ⇒ Object
readonly
Returns the value of attribute if_option.
-
#only_options ⇒ Object
readonly
Returns the value of attribute only_options.
-
#unless_option ⇒ Object
readonly
Returns the value of attribute unless_option.
Instance Method Summary collapse
- #accessible_params_for(controller, dest) ⇒ Object
- #clean_action_option(value) ⇒ Object
-
#initialize(*args) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(*args) ⇒ Rule
Returns a new instance of Rule.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/param_accessible/rule.rb', line 9 def initialize *args if args.length > 1 && args.last.is_a?(Hash) = args.last attributes = args[0..-2] .assert_valid_keys :if, :unless, :only, :except # options = normalize_options options else = {} attributes = args end @if_option = [:if] @unless_option = [:unless] @only_options = clean_action_option [:only] @except_options = clean_action_option [:except] @attributes = normalize_params attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/param_accessible/rule.rb', line 5 def attributes @attributes end |
#except_options ⇒ Object (readonly)
Returns the value of attribute except_options.
7 8 9 |
# File 'lib/param_accessible/rule.rb', line 7 def @except_options end |
#if_option ⇒ Object (readonly)
Returns the value of attribute if_option.
6 7 8 |
# File 'lib/param_accessible/rule.rb', line 6 def if_option @if_option end |
#only_options ⇒ Object (readonly)
Returns the value of attribute only_options.
7 8 9 |
# File 'lib/param_accessible/rule.rb', line 7 def @only_options end |
#unless_option ⇒ Object (readonly)
Returns the value of attribute unless_option.
6 7 8 |
# File 'lib/param_accessible/rule.rb', line 6 def unless_option @unless_option end |
Instance Method Details
#accessible_params_for(controller, dest) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/param_accessible/rule.rb', line 36 def accessible_params_for controller, dest return if @if_option != nil && !controller.send(@if_option) return if @unless_option != nil && controller.send(@unless_option) return if @only_options != nil && !@only_options.include?(controller.action_name) return if @except_options != nil && @except_options.include?(controller.action_name) accessible_hash_for controller.params, @attributes, dest end |
#clean_action_option(value) ⇒ Object
30 31 32 33 34 |
# File 'lib/param_accessible/rule.rb', line 30 def clean_action_option value return if value == nil value = [value] unless value.is_a?(Array) value.collect {|v| v.to_s } end |