Sha256: dab0efd81a48f30f4f994a13866be91a9350ec67fe3553860b29ab6ccff9454f

Contents?: true

Size: 814 Bytes

Versions: 1

Compression:

Stored size: 814 Bytes

Contents

# frozen_string_literal: true

module Dribbble
  module Utils
    module Creatable
      module ClassMethods
        def create(token, attrs)
          @token = token
          res = html_post "/#{api_endpoint}" do |payload|
            available_fields.each { |f| payload[f] = attrs[f] }
          end
          after_create(res)
        end

        # Need to be override if pluralize isn't that naive
        def api_endpoint
          "#{name.split('::').last.downcase}s"
        end

        # Need to be redeclared in the model
        def available_fields
          raise 'You need to redeclare this methods in your model'
        end

        def after_create(res)
          new @token, res
        end
      end

      def self.included(base)
        base.extend(ClassMethods)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dribbble-2.0.0 lib/dribbble/utils/creatable.rb