Class: Rocket::Server::App

Inherits:
Object
  • Object
show all
Defined in:
lib/rocket/server/app.rb

Defined Under Namespace

Classes: NotFoundError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ App

Returns a new instance of App.



30
31
32
# File 'lib/rocket/server/app.rb', line 30

def initialize(attrs={})
  @attributes = attrs
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object

:nodoc:



38
39
40
# File 'lib/rocket/server/app.rb', line 38

def method_missing(meth, *args, &block) # :nodoc:
  (value = attributes[meth.to_s]) ? value : super(meth, *args, &block)
end

Instance Attribute Details

#attributesObject

<< self



28
29
30
# File 'lib/rocket/server/app.rb', line 28

def attributes
  @attributes
end

Class Method Details

.allObject

Returns list of all registered apps.



10
11
12
# File 'lib/rocket/server/app.rb', line 10

def all
  Rocket::Server.apps.to_a.map {|id,app| new(app.merge('id' => id)) }
end

.find(app_id) ⇒ Object

Returns given app if such is registered.

Rocket::Server::App.find("my-test-app-id")     # => #<Rocket::Server::App>
Rocket::Server::App.find("not-registered-app") # raises Rocket::Server::App::NotFoundError


19
20
21
22
23
24
25
# File 'lib/rocket/server/app.rb', line 19

def find(app_id)
  if app = Rocket::Server.apps[app_id] 
    new(app.merge('id' => app_id))
  else 
    raise NotFoundError, "Application '#{app_id}' does not exist!"
  end
end

Instance Method Details

#idObject



34
35
36
# File 'lib/rocket/server/app.rb', line 34

def id
  attributes['id']
end