Module: IronBank::Metadata

Included in:
Resource
Defined in:
lib/iron_bank/metadata.rb

Overview

Metadata to provide accessors to Zuora resources.

Instance Method Summary collapse

Instance Method Details

#excluded_fieldsObject



7
8
9
10
11
12
13
# File 'lib/iron_bank/metadata.rb', line 7

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

#fieldsObject



22
23
24
25
26
# File 'lib/iron_bank/metadata.rb', line 22

def fields
  return [] unless schema

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

#query_custom_fieldsObject



34
35
36
37
38
# File 'lib/iron_bank/metadata.rb', line 34

def query_custom_fields
  return [] unless schema

  @query_custom_fields ||= schema.query_custom_fields - excluded_fields
end

#query_fieldsObject



28
29
30
31
32
# File 'lib/iron_bank/metadata.rb', line 28

def query_fields
  return [] unless schema

  @query_fields ||= schema.query_fields - excluded_fields
end

#resetObject



44
45
46
47
48
49
50
# File 'lib/iron_bank/metadata.rb', line 44

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

  with_schema
end

#schemaObject



40
41
42
# File 'lib/iron_bank/metadata.rb', line 40

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

#single_resource_query_fieldsObject

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.


18
19
20
# File 'lib/iron_bank/metadata.rb', line 18

def single_resource_query_fields
  []
end

#with_schemaObject



52
53
54
55
56
57
# File 'lib/iron_bank/metadata.rb', line 52

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