Module: CronToGoSync::Parser
- Defined in:
- lib/cron_to_go_sync/parser.rb
Defined Under Namespace
Modules: Types Classes: JobContract
Class Method Summary collapse
-
.parse_hash(hash) ⇒ Object
Parse a hash of => properties.
- .parse_toml_file(path) ⇒ Object
Class Method Details
.parse_hash(hash) ⇒ Object
Parse a hash of => properties
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cron_to_go_sync/parser.rb', line 85 def self.parse_hash(hash) contract = JobContract.new hash.map do |key, value| res = contract.call( alias: key, schedule: value[:schedule], dyno_size: value[:dyno_size], command: value[:command], ttl: value[:ttl], enabled: value.fetch(:enabled, true) ) if res.errors.present? raise "Invalid schedule for #{key}: #{res.errors.to_h}" end [key, res.to_h] end.to_h end |
.parse_toml_file(path) ⇒ Object
99 100 101 102 103 |
# File 'lib/cron_to_go_sync/parser.rb', line 99 def self.parse_toml_file(path) hash = TomlRB.load_file(path).with_indifferent_access defaults = hash.delete("DEFAULTS") parse_hash(hash.transform_values { defaults.merge(_1) }) end |