Class: Zae::Parse

Inherits:
Object
  • Object
show all
Defined in:
lib/zae/parse.rb

Overview

Query for configuration files and returns matching ones

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Parse

Returns a new instance of Parse.



23
24
25
26
# File 'lib/zae/parse.rb', line 23

def initialize
  @files = Files.new.all
  @found = found
end

Instance Attribute Details

#found ⇒ Object (readonly)

Returns the value of attribute found.



21
22
23
# File 'lib/zae/parse.rb', line 21

def found
  @found
end

Class Method Details

.executable?(exec) ⇒ Boolean

do executable exist?

Returns:

  • (Boolean)


59
60
61
# File 'lib/zae/parse.rb', line 59

def self.executable?(exec)
  File.executable? exec.to_s
end

Instance Method Details

#all ⇒ Object

List all configuration files

Raises:

  • (ExceptionType)


38
39
40
41
42
43
44
45
46
47
# File 'lib/zae/parse.rb', line 38

def all
  raise ExceptionType, 'Not files found' if @files.nil?

  {}.tap do |elem|
    @files.each do |file|
      name = file.sub_ext('').basename.to_s.to_sym
      elem[name] = one(file)
    end
  end
end

#executable ⇒ Object

package manager's executable location



50
51
52
53
54
55
56
# File 'lib/zae/parse.rb', line 50

def executable
  # return Pathname.new(discovered[:exec]).basename.to_path.to_sym if discovered?

  # get all availables executables
  exec = all.each_value.find { |config| Parse.executable?(config[:exec]) }
  Pathname.new(exec[:exec]).basename.to_path.to_sym
end

#one(file) ⇒ Object

Load and serialize configuration file



33
34
35
# File 'lib/zae/parse.rb', line 33

def one(file)
  JSON.load_file(file, symbolize_names: true)
end