Module: Belafonte::DSL::Definition

Defined in:
lib/belafonte/dsl/definition.rb

Overview

Class methods for defining apps

Instance Method Summary collapse

Instance Method Details

#arg(name, arg_options = {}) ⇒ Object



50
51
52
# File 'lib/belafonte/dsl/definition.rb', line 50

def arg(name, arg_options = {})
  args.push(Belafonte::Argument.new(arg_options.merge({name: name})))
end

#argsObject



46
47
48
# File 'lib/belafonte/dsl/definition.rb', line 46

def args
  meta[:args] ||= []
end

#description(description) ⇒ Object



26
27
28
# File 'lib/belafonte/dsl/definition.rb', line 26

def description(description)
  meta[:description] = description
end

#has_unlimited_arg?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/belafonte/dsl/definition.rb', line 67

def has_unlimited_arg?
  !(args.find {|arg| arg.unlimited?}).nil?
end

#info(item) ⇒ Object



14
15
16
# File 'lib/belafonte/dsl/definition.rb', line 14

def info(item)
  meta[item]
end

#metaObject



10
11
12
# File 'lib/belafonte/dsl/definition.rb', line 10

def meta
  @meta ||= {}
end

#mount(app) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/belafonte/dsl/definition.rb', line 58

def mount(app)
  unless args.any? {|arg| arg.name.to_sym == :command}
    arg :command, times: :unlimited
  end

  raise Belafonte::Errors::CircularMount.new("An app cannot mount itself") if app == self
  subcommands.push(app)
end

#option(name, option_options = {}) ⇒ Object



42
43
44
# File 'lib/belafonte/dsl/definition.rb', line 42

def option(name, option_options = {})
  options.push(Belafonte::Option.new(option_options.merge({name: name})))
end

#optionsObject



38
39
40
# File 'lib/belafonte/dsl/definition.rb', line 38

def options
  meta[:options] ||= []
end

#subcommandsObject



54
55
56
# File 'lib/belafonte/dsl/definition.rb', line 54

def subcommands
  meta[:subcommands] ||= []
end

#summary(summary) ⇒ Object



22
23
24
# File 'lib/belafonte/dsl/definition.rb', line 22

def summary(summary)
  meta[:summary] = summary
end

#switch(name, switch_options = {}) ⇒ Object



34
35
36
# File 'lib/belafonte/dsl/definition.rb', line 34

def switch(name, switch_options = {})
  switches.push(Belafonte::Switch.new(switch_options.merge({name: name})))
end

#switchesObject



30
31
32
# File 'lib/belafonte/dsl/definition.rb', line 30

def switches
  meta[:switches] ||= []
end

#title(title) ⇒ Object



18
19
20
# File 'lib/belafonte/dsl/definition.rb', line 18

def title(title)
  meta[:title] = title
end