Class: Imglab::Source
- Inherits:
-
Object
- Object
- Imglab::Source
- Defined in:
- lib/imglab/source.rb
Constant Summary collapse
- DEFAULT_HTTPS =
true
- DEFAULT_HOST =
"imglab-cdn.net"
- DEFAULT_SUBDOMAINS =
true
Instance Attribute Summary collapse
-
#https ⇒ Object
readonly
Returns the value of attribute https.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#secure_key ⇒ Object
readonly
Returns the value of attribute secure_key.
-
#secure_salt ⇒ Object
readonly
Returns the value of attribute secure_salt.
-
#subdomains ⇒ Object
readonly
Returns the value of attribute subdomains.
Instance Method Summary collapse
-
#host ⇒ String
Returns the host to be used with the source.
-
#initialize(name, host: DEFAULT_HOST, https: DEFAULT_HTTPS, port: nil, secure_key: nil, secure_salt: nil, subdomains: DEFAULT_SUBDOMAINS) ⇒ Imglab::Source
constructor
Returns a Imglab::Source instance with the specified options for the source.
-
#inspect ⇒ String
Overrided inspect method to don’t show sensitive attributes like secure_key and secure_salt.
-
#is_secure? ⇒ Boolean
Returns if the source is secure or not.
-
#path(path) ⇒ String
Returns a the path to be used with the source.
-
#scheme ⇒ String
Returns the URI scheme to be used with the source (“http” or “https”).
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.
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
#https ⇒ Object (readonly)
Returns the value of attribute https.
6 7 8 |
# File 'lib/imglab/source.rb', line 6 def https @https end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/imglab/source.rb', line 6 def name @name end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/imglab/source.rb', line 6 def port @port end |
#secure_key ⇒ Object (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_salt ⇒ Object (readonly)
Returns the value of attribute secure_salt.
6 7 8 |
# File 'lib/imglab/source.rb', line 6 def secure_salt @secure_salt end |
#subdomains ⇒ Object (readonly)
Returns the value of attribute subdomains.
6 7 8 |
# File 'lib/imglab/source.rb', line 6 def subdomains @subdomains end |
Instance Method Details
#host ⇒ String
Returns the host to be used with the source.
38 39 40 |
# File 'lib/imglab/source.rb', line 38 def host @subdomains ? "#{@name}.#{@host}" : @host end |
#inspect ⇒ String
Overrided inspect method to don’t show sensitive attributes like secure_key and secure_salt.
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.
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.
46 47 48 |
# File 'lib/imglab/source.rb', line 46 def path(path) @subdomains ? path : File.join(@name, path) end |
#scheme ⇒ String
Returns the URI scheme to be used with the source (“http” or “https”).
31 32 33 |
# File 'lib/imglab/source.rb', line 31 def scheme @https ? "https" : "http" end |