Class: Oxidized::Source::JSONFile

Inherits:
Source
  • Object
show all
Defined in:
lib/oxidized/source/jsonfile.rb

Direct Known Subclasses

HTTP

Instance Method Summary collapse

Methods inherited from Source

#map_group, #map_model, #node_var_interpolate

Constructor Details

#initializeJSONFile

Returns a new instance of JSONFile.



5
6
7
8
# File 'lib/oxidized/source/jsonfile.rb', line 5

def initialize
  @cfg = Oxidized.config.source.jsonfile
  super
end

Instance Method Details

#loadObject



28
29
30
31
32
33
# File 'lib/oxidized/source/jsonfile.rb', line 28

def load(*)
  data = JSON.parse(open_file.read)
  data = string_navigate_object(data, @cfg.hosts_location) if @cfg.hosts_location?

  transform_json(data)
end

#setupObject

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/oxidized/source/jsonfile.rb', line 10

def setup
  if @cfg.empty?
    Oxidized.asetus.user.source.jsonfile.file      = File.join(Oxidized::Config::ROOT,
                                                               'router.json')
    Oxidized.asetus.user.source.jsonfile.map.name  = "name"
    Oxidized.asetus.user.source.jsonfile.map.model = "model"
    Oxidized.asetus.user.source.jsonfile.gpg       = false
    Oxidized.asetus.save :user
    raise NoConfig, "No source json config, edit #{Oxidized::Config.configfile}"
  end
  require 'gpgme' if @cfg.gpg?

  # map.name is mandatory
  return if @cfg.map.has_key?('name')

  raise InvalidConfig, "map/name is a mandatory source attribute, edit #{Oxidized::Config.configfile}"
end