Class: Remotely::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/remotely/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Application

Returns a new instance of Application.



5
6
7
8
# File 'lib/remotely/application.rb', line 5

def initialize(name, &block)
  @name = name
  instance_eval(&block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/remotely/application.rb', line 3

def name
  @name
end

Instance Method Details

#basic_auth(user = nil, password = nil) ⇒ Object

Set or get BasicAuth credentials.

Parameters:

  • user (String) (defaults to: nil)

    BasicAuth user

  • password (String) (defaults to: nil)

    BasicAuth password



24
25
26
27
# File 'lib/remotely/application.rb', line 24

def basic_auth(user=nil, password=nil)
  return @basic_auth unless user && password
  @basic_auth = [user, password]
end

#connectionObject

Connection to the application (with BasicAuth if it was set).



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/remotely/application.rb', line 31

def connection
  return unless @url

  @connection ||= Faraday::Connection.new(@url) do |b|
    b.request :url_encoded
    b.adapter :net_http
  end

  @connection.basic_auth(*@basic_auth) if @basic_auth
  @connection
end

#url(url = nil) ⇒ Object

Set or get the applications base url.

Parameters:

  • url (String) (defaults to: nil)

    Base url to the appplication



14
15
16
17
# File 'lib/remotely/application.rb', line 14

def url(url=nil)
  return @url unless url
  @url = URI.parse(set_scheme(url)).to_s
end