Sha256: e6425783ca9f4c2a249ddd7b96f420f8c61bdf9cfc4e1c99dc3f1f431b8a700e
Contents?: true
Size: 1.37 KB
Versions: 4
Compression:
Stored size: 1.37 KB
Contents
# frozen_string_literal: true module <%= version_module %> module Resources class <%= singular_class %> < Base model ::<%= singular_class %> # Change it if it maps to a different DB model class # Define the name mapping from API filter params, to model attribute/associations # when they aren't 1:1 # filters_mapping( # 'name': 'name', # 'label': 'association.label_name' # ) # Add dependencies for resource attributes to other attributes and/or model associations # property :href, dependencies: %i[id] <%- if action_enabled?(:create) -%> def self.create(payload) # Assuming the API field names directly map the the model attributes. Massage if appropriate. self.new(model.create(**payload.to_h)) end <%- end -%> <%- if action_enabled?(:update) -%> def self.update(id:, payload:) record = model.find_by(id: id) return nil unless record # Assuming the API field names directly map the the model attributes. Massage if appropriate. record.update(**payload.to_h) self.new(record) end <%- end -%> <%- if action_enabled?(:delete) -%> def self.delete(id:) record = model.find_by(id: id) return nil unless record record.destroy self.new(record) end <%- end -%> end end end
Version data entries
4 entries across 4 versions & 1 rubygems