Sha256: d80cd57e29979a3c5132f30d88bc523de77676d206854e2eea07923635f22089

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 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 delete
        record.destroy
        self
      end
      <%- end -%>  
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
praxis-2.0.0 tasks/thor/templates/generator/scaffold/implementation/resources/item.rb
praxis-2.0.pre.40 tasks/thor/templates/generator/scaffold/implementation/resources/item.rb
praxis-2.0.pre.39 tasks/thor/templates/generator/scaffold/implementation/resources/item.rb
praxis-2.0.pre.38 tasks/thor/templates/generator/scaffold/implementation/resources/item.rb
praxis-2.0.pre.37 tasks/thor/templates/generator/scaffold/implementation/resources/item.rb
praxis-2.0.pre.36 tasks/thor/templates/generator/scaffold/implementation/resources/item.rb
praxis-2.0.pre.35 tasks/thor/templates/generator/scaffold/implementation/resources/item.rb
praxis-2.0.pre.34 tasks/thor/templates/generator/scaffold/implementation/resources/item.rb