Class: EverydayThorUtil::BuilderBuildItems::BuilderCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/everyday_thor_util/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, options = {}, &block) ⇒ BuilderCommand

Returns a new instance of BuilderCommand.



7
8
9
10
11
12
# File 'lib/everyday_thor_util/builder.rb', line 7

def initialize(parent = nil, options = {}, &block)
  @aliases = options.delete(:aliases) if options.has_key?(:aliases) && !parent.nil?
  @parent  = parent
  @options = options
  @body    = block
end

Instance Method Details

#[](name) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/everyday_thor_util/builder.rb', line 50

def [](name)
  if self.commands.has_key?(name)
    self.commands[name]
  elsif self.helpers.has_key?(name)
    self.helpers[name]
  elsif self.flags.has_key?(name)
    self.flags[name]
  else
    nil
  end
end

#[]=(name, obj) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/everyday_thor_util/builder.rb', line 62

def []=(name, obj)
  if obj.is_a?(Hash)
    self.flags[name] = obj
  elsif obj.is_a?(BuilderCommand)
    self.commands[name] = obj
  elsif obj.is_a?(Proc)
    self.helpers[name] = obj
  end
end

#aliasesObject



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

def aliases
  @aliases ||= []
end

#bodyObject



18
19
20
# File 'lib/everyday_thor_util/builder.rb', line 18

def body
  @body
end

#commandsObject



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

def commands
  @commands ||= EverydayThorUtil::BuilderBuildLists::BuilderCommands.new(self)
end

#define(&block) ⇒ Object



26
27
28
# File 'lib/everyday_thor_util/builder.rb', line 26

def define(&block)
  block.call(self.commands, self.flags, self.helpers)
end

#flagsObject



38
39
40
# File 'lib/everyday_thor_util/builder.rb', line 38

def flags
  @flags ||= EverydayThorUtil::BuilderBuildLists::BuilderFlags.new(self)
end

#helpersObject



42
43
44
# File 'lib/everyday_thor_util/builder.rb', line 42

def helpers
  @helpers ||= EverydayThorUtil::BuilderBuildLists::BuilderHelpers.new(self)
end

#leaf?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/everyday_thor_util/builder.rb', line 46

def leaf?
  self.commands.commands.empty? && self.helpers.helpers.empty?
end

#optionsObject



22
23
24
# File 'lib/everyday_thor_util/builder.rb', line 22

def options
  @options
end

#parentObject



14
15
16
# File 'lib/everyday_thor_util/builder.rb', line 14

def parent
  @parent
end