Commit 25adb8bd by ivan Lan

Add method :are_they_your_columns? to Shotengai::Model

parent 042f9186
...@@ -31,7 +31,6 @@ module Shotengai ...@@ -31,7 +31,6 @@ module Shotengai
private private
def resource_params def resource_params
remark_input = params.require(resource_key).fetch(:remark_input, nil)&.map(&:permit!) remark_input = params.require(resource_key).fetch(:remark_input, nil)&.map(&:permit!)
params.require(resource_key).permit( params.require(resource_key).permit(
:count, :shotengai_series_id :count, :shotengai_series_id
).merge({ remark_input: remark_input }) ).merge({ remark_input: remark_input })
......
...@@ -2,5 +2,15 @@ module Shotengai ...@@ -2,5 +2,15 @@ module Shotengai
class Model < ApplicationRecord class Model < ApplicationRecord
self.abstract_class = true self.abstract_class = true
include Shotengai::JsonColumn include Shotengai::JsonColumn
class << self
def are_they_your_columns? columns, type=nil
valid = self.columns.select{ |column| type.nil? || column.type.eql?(type.to_sym) }.map(&:name)
need = Array(columns)
invalid = need - valid
raise Shotengai::WebError.new("Invalid columns: #{invalid}", -1, 400) if invalid.any?
need
end
end
end end
end end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment