Module: Guachiman::Params

Included in:
Permission
Defined in:
lib/guachiman/params.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#read_allowed_paramsObject (readonly)

Returns the value of attribute read_allowed_params.



3
4
5
# File 'lib/guachiman/params.rb', line 3

def read_allowed_params
  @read_allowed_params
end

#write_allowed_paramsObject (readonly)

Returns the value of attribute write_allowed_params.



3
4
5
# File 'lib/guachiman/params.rb', line 3

def write_allowed_params
  @write_allowed_params
end

Instance Method Details

#allow_param(resources, attributes) ⇒ Object



29
30
31
32
# File 'lib/guachiman/params.rb', line 29

def allow_param resources, attributes
  allow_read_param  resources, attributes
  allow_write_param resources, attributes
end

#allow_param?(resource, attribute) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/guachiman/params.rb', line 34

def allow_param? resource, attribute
  allow_write_param?(resource, attribute) && allow_read_param?(resource, attribute)
end

#allowed_paramsObject



25
26
27
# File 'lib/guachiman/params.rb', line 25

def allowed_params
  read_allowed_params & write_allowed_params
end

#permit_params!(params) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/guachiman/params.rb', line 38

def permit_params! params
  if @allow_all
    params.permit!
  elsif write_allowed_params
    write_allowed_params.each do |resource, attributes|
      params[resource] = params[resource].permit(*attributes) if params[resource].respond_to? :permit
    end
  end
end