class IronBank::Schema

Representation of all Zuora objects and their fields for a Zuora tenant, with import/export capabilities.

Attributes

client[R]

Public Class Methods

directory() click to toggle source
# File lib/iron_bank/schema.rb, line 10
def self.directory
  IronBank.configuration.schema_directory
end
excluded_fields() click to toggle source
# File lib/iron_bank/schema.rb, line 41
def self.excluded_fields
  @excluded_fields ||= begin
    IronBank::Resources.constants.each.with_object({}) do |resource, fields|
      fields[resource.to_s] =
        IronBank::Describe::ExcludedFields.call(object_name: resource)
    end
  end
end
export() click to toggle source
# File lib/iron_bank/schema.rb, line 14
def self.export
  FileUtils.mkdir_p(directory) unless Dir.exist?(directory)
  new(IronBank.client).export
  reset
  import
end
for(object_name) click to toggle source
# File lib/iron_bank/schema.rb, line 21
def self.for(object_name)
  import[object_name]
end
import() click to toggle source
# File lib/iron_bank/schema.rb, line 25
def self.import
  @import ||= Dir["#{directory}/*.xml"].each.with_object({}) do |name, data|
    doc    = File.open(name) { |file| Nokogiri::XML(file) }
    object = IronBank::Describe::Object.from_xml(doc)
    data[object.name] = object
  end
end
new(client) click to toggle source
# File lib/iron_bank/schema.rb, line 61
def initialize(client)
  @client = client
end
reset() click to toggle source
# File lib/iron_bank/schema.rb, line 33
def self.reset
  remove_instance_variable(:@import)

  IronBank::Resources.constants.each do |resource|
    IronBank::Resources.const_get(resource).reset
  end
end

Public Instance Methods

export() click to toggle source
# File lib/iron_bank/schema.rb, line 50
def export
  tenant.objects.compact.each do |object|
    object.export
  rescue IronBank::Describe::Object::InvalidXML
    # TODO: log the object error
    next
  end
end
tenant() click to toggle source
# File lib/iron_bank/schema.rb, line 65
def tenant
  @tenant ||= IronBank::Describe::Tenant.from_connection(client.connection)
end