Class: Imglab::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/imglab/source.rb

Constant Summary collapse

DEFAULT_HTTPS =
true
DEFAULT_HOST =
"imglab-cdn.net"
DEFAULT_SUBDOMAINS =
true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, host: DEFAULT_HOST, https: DEFAULT_HTTPS, port: nil, secure_key: nil, secure_salt: nil, subdomains: DEFAULT_SUBDOMAINS) ⇒ Imglab::Source

Returns a Imglab::Source instance with the specified options for the source.

Parameters:

  • name (String)

    the name of the source.

  • host (String) (defaults to: DEFAULT_HOST)

    the host where the imglab server is located, only for imglab on-premises.

  • https (Boolean) (defaults to: DEFAULT_HTTPS)

    specify if the source should use https or not.

  • port (Integer) (defaults to: nil)

    the port where the imglab server is located, only for imglab on-premises.

  • secure_key (String) (defaults to: nil)

    the source secure key.

  • secure_salt (String) (defaults to: nil)

    the source secure salt.

  • subdomains (Boolean) (defaults to: DEFAULT_SUBDOMAINS)

    specify if the source should use subdomains instead of paths to build the host name, only for imglab on-premises.



18
19
20
21
22
23
24
25
26
# File 'lib/imglab/source.rb', line 18

def initialize(name, host: DEFAULT_HOST, https: DEFAULT_HTTPS, port: nil, secure_key: nil, secure_salt: nil, subdomains: DEFAULT_SUBDOMAINS)
  @name = name
  @host = host
  @https = https
  @port = port
  @secure_key = secure_key
  @secure_salt = secure_salt
  @subdomains = subdomains
end

Instance Attribute Details

#httpsObject (readonly)

Returns the value of attribute https.



6
7
8
# File 'lib/imglab/source.rb', line 6

def https
  @https
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/imglab/source.rb', line 6

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/imglab/source.rb', line 6

def port
  @port
end

#secure_keyObject (readonly)

Returns the value of attribute secure_key.



6
7
8
# File 'lib/imglab/source.rb', line 6

def secure_key
  @secure_key
end

#secure_saltObject (readonly)

Returns the value of attribute secure_salt.



6
7
8
# File 'lib/imglab/source.rb', line 6

def secure_salt
  @secure_salt
end

#subdomainsObject (readonly)

Returns the value of attribute subdomains.



6
7
8
# File 'lib/imglab/source.rb', line 6

def subdomains
  @subdomains
end

Instance Method Details

#hostString

Returns the host to be used with the source.

Returns:

  • (String)


38
39
40
# File 'lib/imglab/source.rb', line 38

def host
  @subdomains ? "#{@name}.#{@host}" : @host
end

#inspectString

Overrided inspect method to don’t show sensitive attributes like secure_key and secure_salt.

Returns:

  • (String)


60
61
62
# File 'lib/imglab/source.rb', line 60

def inspect
  "#<#{self.class.name}:#{object_id} @name=#{@name.inspect}, @host=#{@host.inspect}, @https=#{@https.inspect}, @port=#{@port.inspect}, @subdomains=#{@subdomains.inspect}>"
end

#is_secure?Boolean

Returns if the source is secure or not.

Returns:

  • (Boolean)


53
54
55
# File 'lib/imglab/source.rb', line 53

def is_secure?
  @secure_key && @secure_salt
end

#path(path) ⇒ String

Returns a the path to be used with the source.

Parameters:

  • path (String)

Returns:

  • (String)


46
47
48
# File 'lib/imglab/source.rb', line 46

def path(path)
  @subdomains ? path : File.join(@name, path)
end

#schemeString

Returns the URI scheme to be used with the source (“http” or “https”).

Returns:

  • (String)


31
32
33
# File 'lib/imglab/source.rb', line 31

def scheme
  @https ? "https" : "http"
end