Class: Sinew::Main

Inherits:
Scripto::Main
  • Object
show all
Defined in:
lib/sinew/main.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Main

Returns a new instance of Main.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sinew/main.rb', line 11

def initialize(options)
  super(options)

  # init
  @runtime_options = RuntimeOptions.new
  @request_tm = Time.at(0)
  @request_count = 0

  if options[:proxy]
    addr, port = options[:proxy].split(':')
    runtime_options.httparty_options[:http_proxyaddr] = addr
    runtime_options.httparty_options[:http_proxyport] = port || 80
  end
end

Instance Attribute Details

#request_countObject (readonly)

Returns the value of attribute request_count.



9
10
11
# File 'lib/sinew/main.rb', line 9

def request_count
  @request_count
end

#request_tmObject (readonly)

Returns the value of attribute request_tm.



9
10
11
# File 'lib/sinew/main.rb', line 9

def request_tm
  @request_tm
end

#runtime_optionsObject (readonly)

Returns the value of attribute runtime_options.



9
10
11
# File 'lib/sinew/main.rb', line 9

def runtime_options
  @runtime_options
end

Instance Method Details

#cacheObject

http requests and caching



43
44
45
# File 'lib/sinew/main.rb', line 43

def cache
  @cache ||= Cache.new(self)
end

#dslObject



35
36
37
# File 'lib/sinew/main.rb', line 35

def dsl
  @dsl ||= DSL.new(self)
end

#http(method, url, options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/sinew/main.rb', line 47

def http(method, url, options = {})
  request = Request.new(self, method, url, options)

  # try to get from cache
  response = cache.get(request)

  # perform if necessary
  if !response
    response = perform(request)
    cache.set(response)
  end

  # always log error messages
  if response.error?
    puts "xxx http request failed with #{response.code}"
  end

  response
end

#outputObject

output



92
93
94
# File 'lib/sinew/main.rb', line 92

def output
  @output ||= Output.new(self)
end

#quiet?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/sinew/main.rb', line 31

def quiet?
  options[:quiet]
end

#runObject



26
27
28
29
# File 'lib/sinew/main.rb', line 26

def run
  dsl.run
  footer if !quiet?
end