Class: Heroku::Samorau::Check

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

Defined Under Namespace

Classes: CheckError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



77
78
79
80
# File 'lib/heroku/samorau.rb', line 77

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

Instance Attribute Details

#dataObject

Returns the value of attribute data.



73
74
75
# File 'lib/heroku/samorau.rb', line 73

def data
  @data
end

#screenObject

Returns the value of attribute screen.



73
74
75
# File 'lib/heroku/samorau.rb', line 73

def screen
  @screen
end

Instance Method Details

#callObject



104
105
106
107
108
109
110
111
112
# File 'lib/heroku/samorau.rb', line 104

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



86
87
88
89
90
91
92
93
# File 'lib/heroku/samorau.rb', line 86

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

#error(msg) ⇒ Object

Raises:



100
101
102
# File 'lib/heroku/samorau.rb', line 100

def error(msg)
  raise CheckError, msg
end

#run(klass, data) ⇒ Object



95
96
97
98
# File 'lib/heroku/samorau.rb', line 95

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

#test(msg) ⇒ Object



82
83
84
# File 'lib/heroku/samorau.rb', line 82

def test(msg)
  screen.test msg
end

#to_procObject



114
115
116
117
# File 'lib/heroku/samorau.rb', line 114

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