Module: Totem

Defined in:
lib/totem.rb,
lib/totem/shell.rb,
lib/totem/version.rb,
lib/totem/shell_cmds/new.rb,
lib/totem/shell_cmds/base.rb,
lib/totem/shell_cmds/console.rb

Defined Under Namespace

Modules: ShellCmds Classes: Shell

Constant Summary collapse

VERSION =
'0.0.8'

Class Method Summary collapse

Class Method Details

.componentObject



45
46
47
# File 'lib/totem.rb', line 45

def self.component
  return @component ||= ENV['TOTEM_COMPONENT']
end

.component=(val) ⇒ Object



49
50
51
52
53
54
# File 'lib/totem.rb', line 49

def self.component=(val)
  run_callbacks(:before_set_component)
  raise 'component may only be set once and must be set before calling logger' if @logger || @component
  @component = val
  run_callbacks(:after_set_component)
end

.envObject



34
35
36
# File 'lib/totem.rb', line 34

def self.env
  return (@env ||= (ENV['TOTEM_ENV'] || 'development'))
end

.env=(val) ⇒ Object



38
39
40
41
42
43
# File 'lib/totem.rb', line 38

def self.env=(val)
  run_callbacks(:before_set_env)
  raise 'env may only be set once and must be set before calling logger' if @logger || @env
  @env = val
  run_callbacks(:after_set_env)
end

.initialize(root) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/totem.rb', line 10

def self.initialize(root)
  raise 'Already initialized.' if @setup

  # Must stay at top of method.
  run_callbacks(:before_init)

  @setup = true
  @root = root
  Bundler.require(Totem.env.to_sym)
  run_callbacks(:before_first_load_app)
  $LOAD_PATH.unshift(root + '/app')
  load_app
  run_callbacks(:after_first_load_app)

  # Must stay at bottom of method.
  run_callbacks(:after_init)

  return true
end

.instanceObject



56
57
58
# File 'lib/totem.rb', line 56

def self.instance
  return @instance || ENV['TOTEM_INSTANCE']
end

.instance=(val) ⇒ Object



60
61
62
63
64
65
# File 'lib/totem.rb', line 60

def self.instance=(val)
  run_callbacks(:before_set_instance)
  raise 'instance may only be set once and must be set before calling logger' if @logger || @instance
  @instance = val
  run_callbacks(:after_set_instance)
end

.log_file_pathObject



86
87
88
# File 'lib/totem.rb', line 86

def self.log_file_path
  return File.join(root, 'log', "#{process_name}.log")
end

.loggerObject



67
68
69
# File 'lib/totem.rb', line 67

def self.logger
  return @logger || log_to_file
end

.process_nameObject



78
79
80
81
82
83
84
# File 'lib/totem.rb', line 78

def self.process_name
  name = "#{env}"
  name << "_#{component}" if component && component.length > 0
  name << "_#{instance}" if instance && instance.length > 0

  return name
end

.register_callback(type, callback = nil, &block) ⇒ Object



71
72
73
74
75
76
# File 'lib/totem.rb', line 71

def self.register_callback(type, callback=nil, &block)
  @callbacks ||= {}
  (@callbacks[type] ||= []) << (callback || block)

  return true
end

.reloadObject



90
91
92
93
94
# File 'lib/totem.rb', line 90

def self.reload
  run_callbacks(:before_reload)
  load_app
  run_callbacks(:after_reload)
end

.restartObject



96
97
98
99
100
# File 'lib/totem.rb', line 96

def self.restart
  run_callbacks(:before_restart)
  load_app
  run_callbacks(:after_restart)
end

.rootObject



30
31
32
# File 'lib/totem.rb', line 30

def self.root
  return @root
end