Module: Windoo::Mixins::DefaultConnection

Included in:
Windoo
Defined in:
lib/windoo/mixins/default_connection.rb

Overview

Module methods and aliases for dealing with the default connection This is extended into the API module

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extender) ⇒ Object

When this module is extended into a class



20
21
22
# File 'lib/windoo/mixins/default_connection.rb', line 20

def self.extended(extender)
  Windoo.verbose_extend extender, self
end

Instance Method Details

#cnx=(connection) ⇒ APIConnection

Use the given Windoo::Connection object as the default connection, replacing the one that currently exists.

Parameters:

Returns:

  • (APIConnection)

    The connection now being used.



56
57
58
59
60
61
62
# File 'lib/windoo/mixins/default_connection.rb', line 56

def cnx=(connection)
  unless connection.is_a? Windoo::Connection
    raise 'Title Editor connections must be instances of Windoo::Connection'
  end

  @default_connection = connection
end

#connect(url = nil, **params) ⇒ String Also known as: login

Create a new Connection object and use it as the default for all future API calls. This will replace the existing default connection with a totally new one

Parameters:

Returns:

  • (String)

    the to_s output of the new connection



41
42
43
44
45
# File 'lib/windoo/mixins/default_connection.rb', line 41

def connect(url = nil, **params)
  params[:name] ||= :default
  @default_connection = Windoo::Connection.new url, **params
  @default_connection.to_s
end

#default_connectionWindoo::Connection Also known as: cnx

The current default Windoo::Connection instance.

Returns:



28
29
30
# File 'lib/windoo/mixins/default_connection.rb', line 28

def default_connection
  @default_connection ||= Windoo::Connection.new name: :default
end

#disconnectObject Also known as: logout

Disconnect the default connection



66
67
68
# File 'lib/windoo/mixins/default_connection.rb', line 66

def disconnect
  @default_connection.disconnect if @default_connection&.connected?
end