2016-09-24 11:00:46 +08:00
|
|
|
# frozen_string_literal: true
|
2017-11-25 11:23:47 -08:00
|
|
|
|
2016-03-11 17:16:04 +11:00
|
|
|
class PermittedParams < Struct.new(:params)
|
2016-07-26 08:14:23 +08:00
|
|
|
%w(map synapse topic mapping token).each do |kind|
|
2016-03-11 17:16:04 +11:00
|
|
|
define_method(kind) do
|
2016-07-26 08:14:23 +08:00
|
|
|
permitted_attributes = send("#{kind}_attributes")
|
2016-03-11 17:16:04 +11:00
|
|
|
params.require(kind).permit(*permitted_attributes)
|
|
|
|
end
|
|
|
|
alias_method :"api_#{kind}", kind.to_sym
|
|
|
|
end
|
|
|
|
|
2016-07-26 08:14:23 +08:00
|
|
|
alias read_attribute_for_serialization send
|
2016-03-11 17:16:04 +11:00
|
|
|
|
|
|
|
def token_attributes
|
|
|
|
[:description]
|
|
|
|
end
|
2016-07-26 08:14:23 +08:00
|
|
|
|
2016-03-11 17:16:04 +11:00
|
|
|
def map_attributes
|
2017-11-25 11:23:47 -08:00
|
|
|
%i(name desc permission arranged)
|
2016-03-11 17:16:04 +11:00
|
|
|
end
|
2016-07-26 08:14:23 +08:00
|
|
|
|
2016-03-11 17:16:04 +11:00
|
|
|
def synapse_attributes
|
2017-11-25 11:23:47 -08:00
|
|
|
%i(desc category weight permission topic1_id topic2_id)
|
2016-03-11 17:16:04 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
def topic_attributes
|
2017-11-25 11:23:47 -08:00
|
|
|
%i(name desc link permission metacode_id)
|
2016-03-11 17:16:04 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
def mapping_attributes
|
2017-11-25 11:23:47 -08:00
|
|
|
%i(xloc yloc map_id mappable_type mappable_id)
|
2016-03-11 17:16:04 +11:00
|
|
|
end
|
|
|
|
end
|