Class: IronBank::Schema
- Inherits:
-
Object
- Object
- IronBank::Schema
- Defined in:
- lib/iron_bank/schema.rb
Overview
Representation of all Zuora objects and their fields for a Zuora tenant, with import/export capabilities.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
- .directory ⇒ Object
- .excluded_fields ⇒ Object
- .export ⇒ Object
- .for(object_name) ⇒ Object
- .import ⇒ Object
- .reset ⇒ Object
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(client) ⇒ Schema
constructor
A new instance of Schema.
- #tenant ⇒ Object
Constructor Details
#initialize(client) ⇒ Schema
Returns a new instance of Schema.
67 68 69 |
# File 'lib/iron_bank/schema.rb', line 67 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
65 66 67 |
# File 'lib/iron_bank/schema.rb', line 65 def client @client end |
Class Method Details
.directory ⇒ Object
10 11 12 |
# File 'lib/iron_bank/schema.rb', line 10 def self.directory IronBank.configuration.schema_directory end |
.excluded_fields ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/iron_bank/schema.rb', line 41 def self.excluded_fields # NOTE: In some instances the error message from Zuora will not include the # unqueryable fields that need to be excluded. When that happens IronBank's # strategy will be to perform a binary search through the fields listed in the # query -- at the cost of performance due to repeated requests sent to Zuora # as it tries to identify the offending field. # # See: # - https://github.com/zendesk/iron_bank/pull/107 @excluded_fields ||= IronBank::Resources.constants.each.with_object({}) do |resource, fields| fields[resource.to_s] = IronBank::Describe::ExcludedFields.call(object_name: resource) end end |
.export ⇒ Object
14 15 16 17 18 19 |
# File 'lib/iron_bank/schema.rb', line 14 def self.export FileUtils.mkdir_p(directory) new(IronBank.client).export reset import end |
.for(object_name) ⇒ Object
21 22 23 |
# File 'lib/iron_bank/schema.rb', line 21 def self.for(object_name) import[object_name] end |
.import ⇒ Object
25 26 27 28 29 30 31 |
# 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 |
Instance Method Details
#export ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/iron_bank/schema.rb', line 56 def export tenant.objects.compact.each do |object| object.export rescue IronBank::Describe::Object::InvalidXML # TODO: log the object error next end end |
#tenant ⇒ Object
71 72 73 |
# File 'lib/iron_bank/schema.rb', line 71 def tenant @tenant ||= IronBank::Describe::Tenant.from_connection(client.connection) end |