Class: Barrister::Rails::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/barrister-rails.rb

Defined Under Namespace

Classes: BaseEtherealModel, InterfaceProxy

Constant Summary collapse

DEFAULT_BARRISTER_TYPES =
['bool', 'int', 'string', 'float']

Instance Method Summary collapse

Constructor Details

#initialize(transport_or_uri, opts = {}) ⇒ Client

Returns a new instance of Client.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/barrister-rails.rb', line 99

def initialize(transport_or_uri, opts={})
  transport = transport_or_uri.is_a?(String) ? Barrister::HttpTransport.new(transport_or_uri) : transport_or_uri
  @client = Barrister::Client.new(transport)
  @custom_types = Hash.new

  interfaces = @client
    .instance_variable_get('@contract')
    .interfaces

  unless opts[:transmute_to_model] == false
    pairs = interfaces
      .map { |iface| iface.functions }
      .flatten
      .map { |fx| [fx.name.to_sym, { type: fx.returns['type'], is_array: fx.returns['is_array'] } ] }

     = Hash[pairs]
  else
     = {}
  end

  @interface_proxies = interfaces.map { |iface| InterfaceProxy.new iface.name, @client, , opts[:transmute_to_model] != false }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



122
123
124
125
# File 'lib/barrister-rails.rb', line 122

def method_missing(name, *args)
  name_as_string = name.to_s
  @interface_proxies.find { |iface_proxy| iface_proxy.name == name_as_string }
end