Sha256: 4cb5843d2c19f3b88ed750e9866e918c4069f2d5e2d2dacaed7850cd5867db88

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 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 the same
      # filters_mapping(
      #   '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 update(payload:)
        # Assuming the API field names directly map the the model attributes. Massage if appropriate.
        record.update(**payload.to_h)
        self
      end
      <%- end -%>

      <%- if action_enabled?(:delete) -%>
      def self.delete(id:)
        record.destroy
        self
      end
      <%- end -%>  
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
praxis-2.0.pre.33 tasks/thor/templates/generator/scaffold/implementation/resources/item.rb
praxis-2.0.pre.32 tasks/thor/templates/generator/scaffold/implementation/resources/item.rb