Sha256: baa758f8cb0762dd39af96db072e458007e9a614e54a8879ff616b184bedb3e2

Contents?: true

Size: 1.31 KB

Versions: 36

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module LinkedRails
  class Collection
    module Configuration
      extend ActiveSupport::Concern

      module ClassMethods
        private

        def define_default_option_method(option)
          attr_accessor "default_#{option}"
        end

        def define_getter_option_method(option)
          attr_writer option

          define_method(option) do
            resolve_collection_option(option)
          end
        end
      end

      included do
        attr_accessor :iri_template

        LinkedRails::Model::Collections::COLLECTION_CUSTOMIZABLE_OPTIONS.each_key do |option|
          define_default_option_method(option)
        end
        LinkedRails::Model::Collections::COLLECTION_OPTIONS.each_key do |option|
          define_getter_option_method(option)
        end

        def display
          resolve_collection_option(:display)&.to_sym
        end

        def type
          resolve_collection_option(:type)&.to_sym
        end
      end

      private

      def resolve_collection_option(option)
        var_name = :"@#{option}"
        default_method_name = "default_#{option}"

        var = instance_variable_defined?(var_name) ? instance_variable_get(var_name) : try(default_method_name)

        var.respond_to?(:call) ? instance_exec(&var) : var
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
linked_rails-0.0.4.pre.g3aeec2263 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.gacd5f04d4 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.gb0b6aea40 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g792a1b887 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g58af47992 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g0ec6e30ca app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g9e3bcac55 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g222bfeeca app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.gb254a2893 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g2c6c26e86 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.ge881247c3 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.gfabf7e9f5 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g8c045be3a app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g8d7195543 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.gfe77aae19 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.gc866c1806 app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g3e8f5731a app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g58e27be7f app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g96885856b app/models/linked_rails/collection/configuration.rb
linked_rails-0.0.4.pre.g1faca9643 app/models/linked_rails/collection/configuration.rb