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
# 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
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



37
38
39
# File 'lib/sinew/main.rb', line 37

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

#dslObject



29
30
31
# File 'lib/sinew/main.rb', line 29

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

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sinew/main.rb', line 41

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



86
87
88
# File 'lib/sinew/main.rb', line 86

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

#quiet?Boolean

Returns:

  • (Boolean)


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

def quiet?
  options[:quiet]
end

#runObject



20
21
22
23
# File 'lib/sinew/main.rb', line 20

def run
  dsl.run
  footer if !quiet?
end