Class: EasyType::CommandBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_type/command_builder.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CommandBuilder) initialize(context, command, line = '', options = {})

Returns a new instance of CommandBuilder



6
7
8
9
10
11
12
13
14
15
# File 'lib/easy_type/command_builder.rb', line 6

def initialize(context, command, line = '', options = {})
	@context = context
	@command = translate_to_method(command)
	@before = []
	@after = []
	@line = line
	@before_results = []
	@after_results = []
	@options = options
end

Instance Attribute Details

- (Object) after_results (readonly)

Returns the value of attribute after_results



4
5
6
# File 'lib/easy_type/command_builder.rb', line 4

def after_results
  @after_results
end

- (Object) before_results (readonly)

Returns the value of attribute before_results



4
5
6
# File 'lib/easy_type/command_builder.rb', line 4

def before_results
  @before_results
end

- (Object) command

Returns the value of attribute command



3
4
5
# File 'lib/easy_type/command_builder.rb', line 3

def command
  @command
end

- (Object) line

Returns the value of attribute line



3
4
5
# File 'lib/easy_type/command_builder.rb', line 3

def line
  @line
end

- (Object) options (readonly)

Returns the value of attribute options



4
5
6
# File 'lib/easy_type/command_builder.rb', line 4

def options
  @options
end

Instance Method Details

- (Object) <<(line)



17
18
19
20
# File 'lib/easy_type/command_builder.rb', line 17

def <<(line)
	@line << ' ' << line
	self
end

- (Object) after(command = nil)



31
32
33
34
35
36
37
38
# File 'lib/easy_type/command_builder.rb', line 31

def after(command = nil)
	if command
		@after << command
		self
	else
		@after
	end
end

- (Object) before(command = nil)



22
23
24
25
26
27
28
29
# File 'lib/easy_type/command_builder.rb', line 22

def before(command = nil)
	if command
		@before << command
		self
	else
		@before
	end
end

- (Object) execute



40
41
42
43
44
45
46
47
48
49
# File 'lib/easy_type/command_builder.rb', line 40

def execute
	@before.each do | before|
		@before_results << @command.call(before, @options)
	end
	value = @command.call(@line, @options ) if @line
	@after.each do | after|
		@after_results << @command.call(after, @options)
	end
	value
end