Sha256: 2f4f58fa65a607435771ea38c285bd8ec0b2275f416b7e221c7e0fec2baf756a

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module IronBank
  # Metadata to provide accessors to Zuora resources.
  #
  module Metadata
    def excluded_fields
      return [] unless (fields = IronBank.configuration.excluded_fields)

      # Return the field for the given resource name
      # (where the module is extended from)
      fields.fetch(object_name, [])
    end

    # NOTE: For some resources, fields are queryable with some restrictions,
    #       e.g. the `Invoice#body` can only be added to the list of fields if
    #       there is only one invoice in the query response.
    def single_resource_query_fields
      []
    end

    def fields
      return [] unless schema

      @fields ||= schema.fields.map(&:name) - excluded_fields
    end

    def query_fields
      return [] unless schema

      @query_fields ||= schema.query_fields - excluded_fields
    end

    def query_custom_fields
      return [] unless schema

      @query_custom_fields ||= schema.query_custom_fields - excluded_fields
    end

    def schema
      @schema ||= IronBank::Schema.for(object_name)
    end

    def reset
      %i[@fields @query_fields @schema].each do |var|
        remove_instance_variable(var) if instance_variable_defined?(var)
      end

      with_schema
    end

    def with_schema
      fields.each do |field|
        field_name = IronBank::Utils.underscore(field).to_sym
        define_method(:"#{field_name}") { remote[field_name] }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
iron_bank-5.4.1 lib/iron_bank/metadata.rb
iron_bank-5.4.0 lib/iron_bank/metadata.rb
iron_bank-5.3.2 lib/iron_bank/metadata.rb
iron_bank-5.3.0 lib/iron_bank/metadata.rb
iron_bank-5.2.6 lib/iron_bank/metadata.rb
iron_bank-5.2.4 lib/iron_bank/metadata.rb