Module: Gearhead::Extensions::PermittedParams

Included in:
Gear
Defined in:
lib/gearhead/extensions/permitted_params.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
7
# File 'lib/gearhead/extensions/permitted_params.rb', line 4

def self.included(klass)
  klass.define_gear_setting :permitted_params, {}
  klass.define_gear_setting :action_params, {}
end

Instance Method Details

#permit_params(*args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gearhead/extensions/permitted_params.rb', line 9

def permit_params(*args)
  options = args.extract_options!
  if options[:only]
    keys = Array(args[:only]).map(&:to_sym)
    keys.each do |key|
      @_gear_action_params[key] = args
    end
  else
    @_gear_permitted_params = args
  end
end

#permitted_attributes(action) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/gearhead/extensions/permitted_params.rb', line 21

def permitted_attributes(action)
  if attrs = @_gear_action_params[action.to_sym].presence
    attrs
  elsif attrs = @_gear_permitted_params.presence
    attrs
  else
    @resource.columns_hash.keys.map(&:to_sym)
  end
end

#permitted_params(action) ⇒ Object



31
32
33
# File 'lib/gearhead/extensions/permitted_params.rb', line 31

def permitted_params(action)
  permitted_attributes(action)
end