Class: Agen::Builder
- Inherits:
-
Object
- Object
- Agen::Builder
- Defined in:
- lib/agen/builder.rb
Instance Method Summary collapse
- #aliases ⇒ Object
- #construct_alias(aliaz, cmd) ⇒ Object
-
#initialize(commands = [], rcfile = Runner::DEFAULT_RCFILE) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(commands = [], rcfile = Runner::DEFAULT_RCFILE) ⇒ Builder
Returns a new instance of Builder.
5 6 7 8 |
# File 'lib/agen/builder.rb', line 5 def initialize(commands = [], rcfile = Runner::DEFAULT_RCFILE) @commands = commands @rcfile = rcfile end |
Instance Method Details
#aliases ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/agen/builder.rb', line 10 def aliases aliases = [] @commands.map do |cmd| aliaz = cmd.scan(/\b\w/).join # Is is possibly we could overwrite a command here still? Sure. # I will live with it for now. if command_already_exists?(aliaz) || aliases.include?(aliaz) # We could improve to look more like the original command, but again, works for now. aliaz += aliaz[-1] end candidate = construct_alias(aliaz, cmd) if alias_does_not_exist?(candidate) aliases << aliaz {alias: aliaz, full_alias: candidate, command: cmd} end end.compact end |
#construct_alias(aliaz, cmd) ⇒ Object
30 31 32 |
# File 'lib/agen/builder.rb', line 30 def construct_alias(aliaz, cmd) "alias #{aliaz}=\"#{cmd}\"" end |