Class: Anmo::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/anmo/application.rb

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



68
69
70
71
# File 'lib/anmo/application.rb', line 68

def initialize
  ApplicationDataStore.clear_objects
  ApplicationDataStore.clear_requests
end

Instance Method Details

#call(env) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/anmo/application.rb', line 73

def call env
  request = Rack::Request.new(env)

  if request.request_method.upcase == "OPTIONS"
    return [
      200,
      {
        "Access-Control-Allow-Origin" => "*",
        "Access-Control-Allow-Methods" => "*",
        "Access-Control-Allow-Headers" => "X-Requested-With,Content-Type,Authorization"
      },
      ""
    ]
  end

  controller_methods = [
    :alive,
    :version,
    :create_object,
    :objects,
    :requests,
    :delete_all_objects,
    :delete_all_requests
  ]

  method = controller_methods.find {|m| request.path_info =~ /\/?__#{m.to_s.upcase}__\/?/}
  method ||= :process_normal_request
  send(method, request)
end