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