Class: Xplenty::Kensa::Check
- Inherits:
-
Object
- Object
- Xplenty::Kensa::Check
show all
- Defined in:
- lib/xplenty/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.
13
14
15
16
|
# File 'lib/xplenty/kensa/check.rb', line 13
def initialize(data, screen=NilScreen.new)
@data = data
@screen = screen
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
9
10
11
|
# File 'lib/xplenty/kensa/check.rb', line 9
def data
@data
end
|
#screen ⇒ Object
Returns the value of attribute screen.
9
10
11
|
# File 'lib/xplenty/kensa/check.rb', line 9
def screen
@screen
end
|
Instance Method Details
#call ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/xplenty/kensa/check.rb', line 44
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
26
27
28
29
30
31
32
33
|
# File 'lib/xplenty/kensa/check.rb', line 26
def check(msg)
screen.check(msg)
if yield
screen.result(true)
else
raise CheckError
end
end
|
#env ⇒ Object
18
19
20
|
# File 'lib/xplenty/kensa/check.rb', line 18
def env
@data.fetch(:env, 'test')
end
|
#error(msg) ⇒ Object
40
41
42
|
# File 'lib/xplenty/kensa/check.rb', line 40
def error(msg)
raise CheckError, msg
end
|
#run(klass, data) ⇒ Object
35
36
37
38
|
# File 'lib/xplenty/kensa/check.rb', line 35
def run(klass, data)
c = klass.new(data, screen)
instance_eval(&c)
end
|
#test(msg) ⇒ Object
22
23
24
|
# File 'lib/xplenty/kensa/check.rb', line 22
def test(msg)
screen.test msg
end
|
#to_proc ⇒ Object
54
55
56
57
|
# File 'lib/xplenty/kensa/check.rb', line 54
def to_proc
me = self
Proc.new { me.call! }
end
|
#url ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/xplenty/kensa/check.rb', line 59
def url
if data['api'][env].is_a? Hash
base = data['api'][env]['base_url']
uri = URI.parse(base)
base.sub!(uri.query, '') if uri.query
base.sub(uri.path, '')
else
data['api'][env].chomp("/")
end
end
|