Module: Travis::Client::Context

Included in:
Travis
Defined in:
lib/travis/client/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



8
9
10
# File 'lib/travis/client/context.rb', line 8

def connection
  @connection
end

#default_endpointObject

Returns the value of attribute default_endpoint.



7
8
9
# File 'lib/travis/client/context.rb', line 7

def default_endpoint
  @default_endpoint
end

#sessionObject (readonly)

Returns the value of attribute session.



8
9
10
# File 'lib/travis/client/context.rb', line 8

def session
  @session
end

Instance Method Details

#after_request(&block) ⇒ Object



41
42
43
# File 'lib/travis/client/context.rb', line 41

def after_request(&block)
  connection.after_request(&block)
end

#before_request(&block) ⇒ Object



37
38
39
# File 'lib/travis/client/context.rb', line 37

def before_request(&block)
  connection.before_request(&block)
end

#clear_cacheObject



32
33
34
35
# File 'lib/travis/client/context.rb', line 32

def clear_cache
  return unless connected?
  session.response_cache.clear
end

#connect(**options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/travis/client/context.rb', line 10

def connect(**options)
  @call_site ||= caller.first
  if connected? and not defined? @warned
    line = @call_site == caller.first ? @call_site : "#{@call_site} and #{caller.first}"
    $stderr.puts(WARNING % [self, line])
    @warned = true
  end

  @connection = new(**options)
  @session    = @connection.create_session
  @session.define_constants(self)
  @session
end

#connected?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/travis/client/context.rb', line 28

def connected?
  !session.nil?
end

#const_missing(const) ⇒ Object



45
46
47
48
49
50
# File 'lib/travis/client/context.rb', line 45

def const_missing(const)
  super
rescue NameError => error
  message = connected? ? error.message :  "#{error.message}, try running #{self.inspect}.connect"
  raise error, message, caller(2)
end

#new(**options) ⇒ Object



24
25
26
# File 'lib/travis/client/context.rb', line 24

def new(**options)
  Connection.new(**options)
end