Class: SoarScRouting::RouterMeta

Inherits:
Object
  • Object
show all
Includes:
Jsender
Defined in:
lib/soar_sc_routing/router_meta.rb

Constant Summary collapse

SIGNED =
true
UNSIGNED =
false
AUTHORIZED =
true
UNAUTHORIZED =
false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ RouterMeta

Returns a new instance of RouterMeta.



23
24
25
26
27
28
29
30
# File 'lib/soar_sc_routing/router_meta.rb', line 23

def initialize(configuration)
  @configuration = configuration
  @lexicon = {}
  @routing = {}
  @signed_routes = {}
  @service_names = {}
  setup_routing_table
end

Instance Attribute Details

#autenticateObject

Returns the value of attribute autenticate.



21
22
23
# File 'lib/soar_sc_routing/router_meta.rb', line 21

def autenticate
  @autenticate
end

#configurationObject

Returns the value of attribute configuration.



15
16
17
# File 'lib/soar_sc_routing/router_meta.rb', line 15

def configuration
  @configuration
end

#lexiconObject

Returns the value of attribute lexicon.



16
17
18
# File 'lib/soar_sc_routing/router_meta.rb', line 16

def lexicon
  @lexicon
end

#policy_amObject

Returns the value of attribute policy_am.



20
21
22
# File 'lib/soar_sc_routing/router_meta.rb', line 20

def policy_am
  @policy_am
end

#routingObject

Returns the value of attribute routing.



17
18
19
# File 'lib/soar_sc_routing/router_meta.rb', line 17

def routing
  @routing
end

#service_namesObject

Returns the value of attribute service_names.



19
20
21
# File 'lib/soar_sc_routing/router_meta.rb', line 19

def service_names
  @service_names
end

#signed_routesObject

Returns the value of attribute signed_routes.



18
19
20
# File 'lib/soar_sc_routing/router_meta.rb', line 18

def signed_routes
  @signed_routes
end

Instance Method Details

#access_managerObject



32
33
34
# File 'lib/soar_sc_routing/router_meta.rb', line 32

def access_manager
  @policy_am
end

#add_route(path, description, &block) ⇒ Object



50
51
52
53
# File 'lib/soar_sc_routing/router_meta.rb', line 50

def add_route(path, description, &block)
  resource = SoarScRouting::Resource.new(description, generate_id(path))
  add_resource_route(path, resource, UNSIGNED, AUTHORIZED, &block)
end

#add_signed_route(path, description, &block) ⇒ Object



60
61
62
63
# File 'lib/soar_sc_routing/router_meta.rb', line 60

def add_signed_route(path, description, &block)
  resource = SoarScRouting::Resource.new(description, generate_id(path))
  add_resource_route(path, resource, SIGNED, AUTHORIZED, &block)
end

#add_signed_unauthorized_route(path, description, &block) ⇒ Object



65
66
67
68
# File 'lib/soar_sc_routing/router_meta.rb', line 65

def add_signed_unauthorized_route(path, description, &block)
  resource = SoarScRouting::Resource.new(description, generate_id(path))
  add_resource_route(path, resource, SIGNED, UNAUTHORIZED, &block)
end

#add_unsigned_unauthorized_route(path, description, &block) ⇒ Object



55
56
57
58
# File 'lib/soar_sc_routing/router_meta.rb', line 55

def add_unsigned_unauthorized_route(path, description, &block)
  resource = SoarScRouting::Resource.new(description, generate_id(path))
  add_resource_route(path, resource, UNSIGNED, UNAUTHORIZED, &block)
end

#register_route(detail, startup_flow_id = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/soar_sc_routing/router_meta.rb', line 36

def register_route(detail, startup_flow_id = nil)
  validate_detail(detail)
  info("Registering service: #{detail}", startup_flow_id)
  resource = SoarScRouting::Resource.new(detail['description'], "#{detail['service_name']}", detail['method'].upcase, detail['params'])
  add_resource_route(detail['path'], resource, interpret_secured(detail), interpret_authorized(detail)) do |request|
    if detail['controller']
      delegate_to_controller_and_renderer(detail, startup_flow_id, request)
    elsif detail['action']
      http_code, headers, body = detail['action'].call(request)
      [http_code, headers, [body]]
    end
  end
end