Sha256: 11538f2ff8228e6f70ce5a31b97d269a1adb991a1f35ba99b62ccd717db886bc

Contents?: true

Size: 871 Bytes

Versions: 7

Compression:

Stored size: 871 Bytes

Contents

# frozen_string_literal: true

module Gecko
  module Helpers
    # Helper for registering valid record types
    module RecordHelper
      # Registers a record type on the Gecko::Client
      #
      # @example
      #  class Gecko::Client
      #    record :Invoice
      #  end
      #
      # @return [undefined]
      #
      # @api private
      def record(record_type)
        define_method record_type do
          adapter_cache = "@#{record_type}_cache".to_sym
          unless instance_variable_defined?(adapter_cache)
            adapter_name  = "#{record_type}Adapter".to_sym
            adapter_klass = Gecko::Record.const_get(adapter_name)
            adapter = adapter_klass.new(self, record_type)
            instance_variable_set(adapter_cache, adapter)
          end
          instance_variable_get(adapter_cache)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gecko-ruby-0.12.3 lib/gecko/helpers/record_helper.rb
gecko-ruby-0.12.2 lib/gecko/helpers/record_helper.rb
gecko-ruby-0.12.1 lib/gecko/helpers/record_helper.rb
gecko-ruby-0.12.0 lib/gecko/helpers/record_helper.rb
gecko-ruby-0.11.1 lib/gecko/helpers/record_helper.rb
gecko-ruby-0.11.0 lib/gecko/helpers/record_helper.rb
gecko-ruby-0.10.0 lib/gecko/helpers/record_helper.rb