Class: Putpaws::ScheduleConfig

Inherits:
Struct
  • Object
show all
Defined in:
lib/putpaws/schedule_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



6
7
8
# File 'lib/putpaws/schedule_config.rb', line 6

def args
  @args
end

#commandObject

Returns the value of attribute command

Returns:

  • (Object)

    the current value of command



6
7
8
# File 'lib/putpaws/schedule_config.rb', line 6

def command
  @command
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



6
7
8
# File 'lib/putpaws/schedule_config.rb', line 6

def name
  @name
end

#networkObject

Returns the value of attribute network

Returns:

  • (Object)

    the current value of network



6
7
8
# File 'lib/putpaws/schedule_config.rb', line 6

def network
  @network
end

#regionObject

Returns the value of attribute region

Returns:

  • (Object)

    the current value of region



6
7
8
# File 'lib/putpaws/schedule_config.rb', line 6

def region
  @region
end

#targetObject

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



6
7
8
# File 'lib/putpaws/schedule_config.rb', line 6

def target
  @target
end

Class Method Details

.allObject



32
33
34
35
36
# File 'lib/putpaws/schedule_config.rb', line 32

def self.all
  load.map{|k,v|
    new(build_args(k, v))
  }
end

.build_args(name, config_args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/putpaws/schedule_config.rb', line 18

def self.build_args(name, config_args)
  region = config_args.delete(:region)
  network = config_args.delete(:network)
  target = config_args.delete(:target)
  command = config_args.delete(:command)
  {
    name: name.to_s, 
    region: region, 
    network: network, 
    target: target, 
    command: command,
  }.merge(args: config_args)
end

.find(name) ⇒ Object



38
39
40
41
42
43
# File 'lib/putpaws/schedule_config.rb', line 38

def self.find(name)
  schedule_data = load
  data = schedule_data[name.to_sym]
  return nil unless data
  new(build_args(name, data))
end

.load(path_prefix: '.putpaws') ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/putpaws/schedule_config.rb', line 9

def self.load(path_prefix: '.putpaws')
  @schedule_data ||= begin
    path = Pathname.new(path_prefix).join("schedule.json").to_s
    data = File.exist?(path) ?
      JSON.parse(File.read(path), symbolize_names: true).to_h :
      {}
  end
end