Class: Irumugam::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/irumugam/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, service_block) ⇒ Service

Returns a new instance of Service.



4
5
6
7
8
9
10
# File 'lib/irumugam/service.rb', line 4

def initialize(name, service_block)
  @name, @block = name, service_block
  @before_blocks = {} 
  @after_blocks = {}
  @paths = ServiceRegistry.instance.paths
  instance_eval &service_block
end

Instance Attribute Details

#after_blocksObject

Returns the value of attribute after_blocks.



3
4
5
# File 'lib/irumugam/service.rb', line 3

def after_blocks
  @after_blocks
end

#before_blocksObject

Returns the value of attribute before_blocks.



3
4
5
# File 'lib/irumugam/service.rb', line 3

def before_blocks
  @before_blocks
end

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/irumugam/service.rb', line 3

def block
  @block
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/irumugam/service.rb', line 3

def name
  @name
end

#pathsObject

Returns the value of attribute paths.



3
4
5
# File 'lib/irumugam/service.rb', line 3

def paths
  @paths
end

#rest_end_pointObject

Returns the value of attribute rest_end_point.



3
4
5
# File 'lib/irumugam/service.rb', line 3

def rest_end_point
  @rest_end_point
end

#test_hostObject

Returns the value of attribute test_host.



3
4
5
# File 'lib/irumugam/service.rb', line 3

def test_host
  @test_host
end

Instance Method Details

#after(type = :each, &after_block) ⇒ Object



14
15
16
# File 'lib/irumugam/service.rb', line 14

def after(type=:each, &after_block)
  after_blocks[type] = after_block
end

#before(type = :each, &before_block) ⇒ Object



11
12
13
# File 'lib/irumugam/service.rb', line 11

def before(type=:each, &before_block)
  before_blocks[type] = before_block
end

#end_point(name) ⇒ Object



17
18
19
# File 'lib/irumugam/service.rb', line 17

def end_point(name)
  @rest_end_point = name
end

#host(val) ⇒ Object



20
21
22
# File 'lib/irumugam/service.rb', line 20

def host(val)
  @test_host=val
end

#http_method(method, path, options, contract_block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/irumugam/service.rb', line 29

def http_method(method,path,options,contract_block)
  defaults = {:accept=>"application/json", 
              :method=>method, 
              :path=>path,
              :test_host => @test_host,
              :params=>{}, 
              :block=>contract_block,
              :service=>self}
  defaults.merge!(options)
  paths[path] ||= []
  paths[path] << Contract.new(defaults)
end