Class: Anonymise::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/anonymise/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Resource



8
9
10
# File 'lib/anonymise/resource.rb', line 8

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/anonymise/resource.rb', line 7

def path
  @path
end

Instance Method Details

#contentObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/anonymise/resource.rb', line 12

def content
  if @path.nil?
    puts 'Path to config file is required'.colorize(:red)
    exit
  end
  if @path.start_with?('http')
    # get this from the URL via tempfile.
    yml_file = ''
  elsif File.exist?(@path)
    yml_file = File.open(@path)
  else
    puts 'File does not exist'.colorize(:red)
    exit
  end
  content = YAML.safe_load(yml_file)
  yml_file.close
  if content.empty?
    puts 'Config file is empty kindly check https://github.com/thirunjuguna/anonymise/blob/master/anonymise.yml'
    exit
  end
  content
end