Class: Trema::App

Inherits:
NetworkComponent show all
Includes:
Daemon
Defined in:
ruby/trema/app.rb

Overview

Trema applications

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Daemon

#pid_file, #restart!, #run, #run!, #running?, #shutdown, #shutdown!

Methods inherited from NetworkComponent

[], add, clear, each, inherited, size

Constructor Details

- (App) initialize(stanza)

Creates a new Trema application from DSL::Run

Examples:

app = Trema::App.new( stanza )


51
52
53
54
55
56
57
58
59
60
61
62
# File 'ruby/trema/app.rb', line 51

def initialize stanza
  @stanza = stanza
  if /\.rb\Z/=~ @stanza.fetch( :name )  # ruby?
    require "trema"
    path = @stanza.fetch( :path )
    ARGV.replace [ path ]
    $LOAD_PATH << File.dirname( path )
    Trema.module_eval IO.read( path )
  else
    App.add self
  end
end

Instance Attribute Details

- (Trema::DSL::Stanza) stanza (readonly)

A map of key-value pair settings for trema's dsl run{} syntax.

Returns:



35
36
37
# File 'ruby/trema/app.rb', line 35

def stanza
  @stanza
end

Instance Method Details

- (String) command

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns application's command to execute

Returns:



103
104
105
# File 'ruby/trema/app.rb', line 103

def command
  "#{ @stanza[ :path ] } --name #{ name }"
end

- (App) daemonize!

Runs as a daemon

Examples:

app.daemonize! #=> self

Returns:



90
91
92
93
# File 'ruby/trema/app.rb', line 90

def daemonize!
  sh [ command, "-d", @stanza[ :options ] ].compact.join( " " )
  self
end

- (String) name

Returns the name of application

Examples:

app.name #=> "Trema Tetris"

Returns:



75
76
77
# File 'ruby/trema/app.rb', line 75

def name
  @stanza[ :name ]
end