class Barrister::Rails::Client::InterfaceProxy

Attributes

name[R]

Public Class Methods

new(name, client, fx_metadata) click to toggle source
# File lib/barrister-rails.rb, line 34
def initialize(name, client, fx_metadata)
  @name               = name
  @client             = client
  @fx_metadata        = fx_metadata
end

Public Instance Methods

all_struct_fields(arr, struct, structs) click to toggle source
# File lib/barrister-rails.rb, line 82
def all_struct_fields(arr, struct, structs)
  struct["fields"].each do |f|
    arr << f
  end

  if struct["extends"]
    parent = structs[struct["extends"]]
    if parent
      return all_struct_fields(arr, parent, structs)
    end
  end

  return arr
end
attributes_for_type(type) click to toggle source
# File lib/barrister-rails.rb, line 74
def attributes_for_type(type)
  structs = @client
    .instance_variable_get('@contract')
    .instance_variable_get('@structs')

  all_struct_fields([], structs[type], structs).map { |f| f['name'] }
end
cast(result, type, is_array) click to toggle source
# File lib/barrister-rails.rb, line 64
def cast(result, type, is_array)
  klass = ensure_const(type)

  if is_array
    result.map { |result| klass.new result }
  else
    klass.new result
  end
end
ensure_const(type) click to toggle source
# File lib/barrister-rails.rb, line 50
def ensure_const(type)
  return Object.const_get(type) if Object.const_defined?(type)

  klass = Class.new(BaseEtherealModel)

  a = attributes_for_type(type).map { |name| "attribute :#{name};" }

  klass.class_eval a.join('')

  Object.send(:const_set, type, klass)

  klass
end
method_missing(name, *args) click to toggle source
# File lib/barrister-rails.rb, line 40
def method_missing(name, *args)
  result = @client.send(@name).send(name, *args)

  if DEFAULT_BARRISTER_TYPES.include?(@fx_metadata[name][:type]) == false
    cast result, @fx_metadata[name][:type], @fx_metadata[name][:is_array]
  else
    result
  end
end