Sha256: 61f6274ff78bc03e8c3b32049e15e3fbabae8ce70177684a23bc3f0ef866d45b

Contents?: true

Size: 1.46 KB

Versions: 17

Compression:

Stored size: 1.46 KB

Contents

module JSONAPIonify::Api
  module Resource::Builders
    extend ActiveSupport::Concern
    extend JSONAPIonify::Autoload

    autoload_all

    FALSEY_STRINGS = JSONAPIonify::FALSEY_STRINGS
    TRUTHY_STRINGS = JSONAPIonify::TRUTHY_STRINGS

    module ClassMethods
      include JSONAPIonify::Structure

      def build_resource(**options, &block)
        ResourceBuilder.build(self, **options)
      end

      def build_resource_collection(context:, collection:, include_cursors: false, &block)
        collection.each_with_object(
          Collections::Resources.new
        ) do |instance, resources|
          resources << build_resource(context: context, instance: instance, include_cursor: include_cursors, &block)
        end
      end

      def build_resource_identifier(instance:)
        ResourceIdentiferBuilder.build(self, instance: instance)
      end

      def build_resource_identifier_collection(collection:)
        collection.each_with_object(
          Collections::ResourceIdentifiers.new
        ) do |instance, resource_identifiers|
          resource_identifiers << build_resource_identifier(instance: instance)
        end
      end

      def build_cursor(**options)
        CursorBuilder.build(self, **options)
      end

      def build_id(**options)
        IdBuilder.build(self, **options)
      end

    end

    delegated_methods = ClassMethods.instance_methods - instance_methods
    included do
      delegate(*delegated_methods, to: :class)
    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
jsonapionify-0.12.10 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.12.9 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.12.8 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.12.7 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.12.5 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.12.4 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.12.3 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.12.2 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.12.1 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.12.0 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.11.11 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.11.10 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.11.9 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.11.8 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.11.7 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.11.6 lib/jsonapionify/api/resource/builders.rb
jsonapionify-0.11.5 lib/jsonapionify/api/resource/builders.rb