class EventbriteSDK::Resource::SchemaDefinition

Attributes

attrs[R]
comparable[R]
read_only_keys[R]
resource_name[R]

Public Class Methods

new(resource_name) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 4
def initialize(resource_name)
  @attrs = {}
  @read_only_keys = Set.new
  @comparable = FieldComparable.new
  @resource_name = resource_name
end

Public Instance Methods

defined_keys() click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 34
def defined_keys
  attrs.keys
end
dirty_comparable(field) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 38
def dirty_comparable(field)
  comparable.value_for(attrs[field.key], field)
end
type(key) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 30
def type(key)
  attrs[key]
end
writeable?(key) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 26
def writeable?(key)
  whitelisted_attribute?(key) && !read_only?(key)
end

Private Instance Methods

add_field(_options, value, method) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 51
def add_field(_options, value, method)
  @attrs[value] = method
  send(:"#{method}_expansion", value)
end
add_field_options(opts, value, _method) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 46
def add_field_options(opts, value, _method)
  options = opts.first
  @read_only_keys << value if options && options[:read_only]
end
currency_expansion(value) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 61
def currency_expansion(value)
  generic_expansion(%w[currency display value], value)
end
datetime_expansion(value) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 65
def datetime_expansion(value)
  generic_expansion(%w[local utc timezone], value)
end
generic_expansion(types, value) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 73
def generic_expansion(types, value)
  types.map { |exp| @attrs["#{value}.#{exp}"] = :string }
end
multipart_expansion(value) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 69
def multipart_expansion(value)
  generic_expansion(%i[html text], value)
end
read_only?(key) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 77
def read_only?(key)
  read_only_keys.member?(key)
end
whitelisted_attribute?(key) click to toggle source
# File lib/eventbrite_sdk/resource/schema_definition.rb, line 81
def whitelisted_attribute?(key)
  if attrs.has_key?(key)
    true
  else
    raise InvalidAttribute.new(
      "attribute `#{key}` not present in #{resource_name}"
    )
  end
end