Class: Resty::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/resty/options.rb

Constant Summary collapse

CONFIG_FILE =
"#{Dir.home}/.ruby_resty.yml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Options

Returns a new instance of Options.



9
10
11
12
13
14
15
16
17
# File 'lib/resty/options.rb', line 9

def initialize(options)
  @options = options

  if options[:headers]
    options[:headers] = Options.parse_headers(options[:headers])
  elsif host_alias
    load_config_file
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/resty/options.rb', line 5

def options
  @options
end

Class Method Details

.build_pair(header) ⇒ Object



47
48
49
50
# File 'lib/resty/options.rb', line 47

def self.build_pair(header)
  pair = header.split(":")
  { pair.first.to_sym => pair.last }
end

.parse_headers(headers) ⇒ Object



43
44
45
# File 'lib/resty/options.rb', line 43

def self.parse_headers(headers)
  headers.inject({}) { |hash, header| hash.merge(build_pair(header)) }
end

Instance Method Details

#headersObject



31
32
33
# File 'lib/resty/options.rb', line 31

def headers
  options[:headers] || {}
end

#hostObject



19
20
21
# File 'lib/resty/options.rb', line 19

def host
  options[:host]
end

#host_aliasObject



27
28
29
# File 'lib/resty/options.rb', line 27

def host_alias
  options[:alias]
end

#passwordObject



39
40
41
# File 'lib/resty/options.rb', line 39

def password
  options[:password]
end

#usernameObject



35
36
37
# File 'lib/resty/options.rb', line 35

def username
  options[:username]
end

#verbose?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/resty/options.rb', line 23

def verbose?
  options[:verbose] ? true : false
end