Class: AliasChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/shell/alias_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ AliasChecker

Returns a new instance of AliasChecker.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/shell/alias_checker.rb', line 4

def initialize(filename)
  @filename = filename

  if !File.exist?(File.expand_path(filename))
    return
  end

  file_contents = File.open(File.expand_path(filename), 'r').read
  lines = file_contents.split("\n")
  @aliases = {}
  lines.each do |l|
    al = AliasLine.new(l)
    next unless al.valid?
    @aliases[al.alias_name] = al.command
  end
end

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases.



2
3
4
# File 'lib/shell/alias_checker.rb', line 2

def aliases
  @aliases
end

#filenameObject

Returns the value of attribute filename.



2
3
4
# File 'lib/shell/alias_checker.rb', line 2

def filename
  @filename
end

Instance Method Details

#exist?(alias_name) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/shell/alias_checker.rb', line 21

def exist?(alias_name)
  @aliases && !!@aliases[alias_name]
end