Sha256: 28c8faf38ccb29800696fa298e6e6c2b424df7a46c0d1bbe37bbb2ffcda30f13

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 Bytes

Contents

# frozen_string_literal: true

class BasicSerializer
  module DSL
    def attributes
      @attributes ||= {}
    end

    def attribute(name, type = nil)
      attributes[name] = type || :default

      return if @defined_methods&.include?(name)

      @defined_methods ||= Set.new
      @defined_methods << name

      define_method(name) { object.public_send(name) }
    end

    def model_name(name)
      @model_name = name
    end

    def custom_model_name
      @custom_model_name ||= @model_name || name.delete_suffix("Serializer")
    end

    def schema_ref(ref)
      @schema_ref = ref
    end

    def format(name, pretty: false)
      @format = { name: name, pretty: pretty }
    end

    def format_settings
      @format_settings ||= {}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
basic_serializer-0.1.8 lib/basic_serializer/dsl.rb