Sha256: 93f38c831bd1488c022f5152ce6e88aee9811af0e97ee42536740cc8d4a0ba87

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 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 schema
      @schema ||= IronBank::Schema.for(object_name)
    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

1 entries across 1 versions & 1 rubygems

Version Path
iron_bank-4.0.2 lib/iron_bank/metadata.rb