Class: Heroku::Kensa::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku/kensa/check.rb

Defined Under Namespace

Classes: CheckError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, screen = NilScreen.new) ⇒ Check

Returns a new instance of Check.



14
15
16
17
# File 'lib/heroku/kensa/check.rb', line 14

def initialize(data, screen=NilScreen.new)
  @data = data
  @screen = screen
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/heroku/kensa/check.rb', line 10

def data
  @data
end

#screenObject

Returns the value of attribute screen.



10
11
12
# File 'lib/heroku/kensa/check.rb', line 10

def screen
  @screen
end

Instance Method Details

#api_requires?(feature) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/heroku/kensa/check.rb', line 76

def api_requires?(feature)
  data["api"].fetch("requires", []).include?(feature)
end

#callObject



49
50
51
52
53
54
55
56
57
# File 'lib/heroku/kensa/check.rb', line 49

def call
  call!
  true
rescue CheckError => boom
  screen.result(false)
  screen.error boom.message if boom.message != boom.class.name

  false
end

#check(msg) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/heroku/kensa/check.rb', line 27

def check(msg)
  screen.check(msg)
  if yield
    screen.result(true)
  else
    raise CheckError
  end
end

#envObject



19
20
21
# File 'lib/heroku/kensa/check.rb', line 19

def env
  @data.fetch(:env, 'test')
end

#error(msg) ⇒ Object

Raises:



41
42
43
# File 'lib/heroku/kensa/check.rb', line 41

def error(msg)
  raise CheckError, msg
end

#run(klass, data) ⇒ Object



36
37
38
39
# File 'lib/heroku/kensa/check.rb', line 36

def run(klass, data)
  c = klass.new(data, screen)
  instance_eval(&c)
end

#test(msg) ⇒ Object



23
24
25
# File 'lib/heroku/kensa/check.rb', line 23

def test(msg)
  screen.test msg
end

#to_procObject



59
60
61
62
# File 'lib/heroku/kensa/check.rb', line 59

def to_proc
  me = self
  Proc.new { me.call! }
end

#urlObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/heroku/kensa/check.rb', line 64

def url
  if data['api'][env].is_a? Hash
    base = data['api'][env]['base_url']
    uri = URI.parse(base)
    uri.query = nil
    uri.path = ''
    uri.to_s
  else
    data['api'][env].chomp("/")
  end
end

#warning(msg) ⇒ Object



45
46
47
# File 'lib/heroku/kensa/check.rb', line 45

def warning(msg)
  screen.warning msg
end