Class: Tbox::Add

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/tb-cli/cli/add.rb

Overview

Class for adding components to your torquebox.yml, queues.yml or topics.yml file.

Instance Method Summary collapse

Instance Method Details

#applicationObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/tb-cli/cli/add.rb', line 20

def application
  y = ConfigFile.new destination_root
  if options.root_loc || options.env
    y.add_config('application', 'root', options.root_loc) if options.root_loc
    y.add_config('application', 'env', options.env) if options.env
    replace_yaml(y.yaml)
  else
    puts "You need to specify either --root-loc or --env"
  end
end

#authObject



210
211
212
213
214
# File 'lib/tb-cli/cli/add.rb', line 210

def auth
  y = ConfigFile.new destination_root
  y.add_config('auth', options.auth_type, { "domain" => options.domain })
  replace_yaml(y.yaml)
end

#environmentObject



80
81
82
83
84
85
86
# File 'lib/tb-cli/cli/add.rb', line 80

def environment
  y = ConfigFile.new destination_root
  options.options.each_pair { |k,v|
    y.add_config('environment', k, v)
  }
  replace_yaml(y.yaml)
end

#help(meth = nil) ⇒ Object



240
241
242
243
# File 'lib/tb-cli/cli/add.rb', line 240

def help(meth=nil)
  puts INIT
  super
end

#jobObject



185
186
187
188
189
190
191
192
193
# File 'lib/tb-cli/cli/add.rb', line 185

def job
  y = ConfigFile.new destination_root
  opts = {}
  opts['job'] = options.job_class
  opts['cron'] = options.cron
  opts['description'] = options.description if options.description
  y.add_config('jobs', options.job_name, opts)
  replace_yaml(y.yaml)
end

#messagingObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/tb-cli/cli/add.rb', line 145

def messaging
  if options.queue == nil && options.topic == nil
    puts "You must specify either a topic or a queue you're configuring a handler for"
  else
    if options.handler_class
      y = ConfigFile.new destination_root
      messaging = y.add_config["messaging"] || {}
      if options.queue
        messaging[options.queue] = options.handler_class
      elsif options.topic
        messaging[options.topic] = options.handler_class
      end
      y.add_config["messaging"] = messaging
      puts y.yaml
      replace_yaml(y.yaml)
    else
      puts "You must specify a --handler-class"
    end
  end
end

#poolingObject



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/tb-cli/cli/add.rb', line 222

def pooling
  y = ConfigFile.new destination_root
  thing = {}
  thing["pooling"] = {}
  if [ 'web', 'jobs', 'messaging', 'services' ].include? options.subsystem
    if options.bounded
      y.add_config('pooling', options.subsystem, options.bounded)
    elsif options.shared
      y.add_config('pooling', options.subsystem, 'shared')
    elsif options.global
      y.add_config('pooling', options.subsystem, 'global')
    end
    replace_yaml(y.yaml)
  else
    puts "subsystem must be one of: web, job, messaging, or services"
  end
end

#queueObject



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/tb-cli/cli/add.rb', line 104

def queue
  # TODO: Add external queues and hosts (see section 7.2.3.3 for details)
  file = 'queues.yml'
  y = ConfigFile.new destination_root, file
  if (options.not_durable && options.name)
    y.add_config("/queues/#{options.name}", "durable: #{!options.not_durable}")
  elsif (options.name)
    y.add_config("/queues/#{options.name}")
  end
  replace_yaml(y.yaml, file) 
end

#rubyObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/tb-cli/cli/add.rb', line 67

def ruby
  y = ConfigFile.new destination_root
  if [ 1.8, 1.9 ].include? options.version
    y.add_config('ruby', 'version', options.version)
  end
  if [ 'jit', 'force', 'off' ].include? options.compile_mode
    y.add_config('ruby', 'compile_mode', options.compile_mode)
  end
  replace_yaml(y.yaml)
end

#serviceObject



199
200
201
202
203
204
205
# File 'lib/tb-cli/cli/add.rb', line 199

def service
  y = ConfigFile.new destination_root
  opts = options.params
  opts["singleton"] = true if options.singleton
  y.add_config('services', options.name, opts)
  replace_yaml(y.yaml)
end

#taskObject



169
170
171
172
173
174
175
176
177
# File 'lib/tb-cli/cli/add.rb', line 169

def task
  y = ConfigFile.new destination_root
  if options.concurrency
    y.add_config('tasks', options.name, { "concurrency" => options.concurrency })
  else
    y.add_config('tasks', options.name)
  end
  replace_yaml(y.yaml)
end

#topicObject



125
126
127
128
129
130
131
# File 'lib/tb-cli/cli/add.rb', line 125

def topic
  # TODO: Add external queues and hosts (see section 7.2.3.3 for details)
  file = 'topics.yml'
  y = ConfigFile.new destination_root, file
  y.add_config("/topics/#{options.name}")
  replace_yaml(y.yaml, file)
end

#webObject



48
49
50
51
52
53
54
55
# File 'lib/tb-cli/cli/add.rb', line 48

def web
  y = ConfigFile.new destination_root
  y.add_config('web', 'rackup', options.rackup) if options.rackup
  y.add_config('web', 'host', options.host) if options.host
  y.add_config('web', 'context', options.context) if options.context
  y.add_config('web', 'static', options.static) if options.static
  replace_yaml(y.yaml)
end