Class: Availability::Config
- Inherits:
-
Object
- Object
- Availability::Config
- Includes:
- ConfigValueParser
- Defined in:
- lib/availability/config.rb
Overview
Loads, normalizes, and validates generator configuration.
Constant Summary collapse
- TOP_LEVEL_KEYS =
%w[ enabled timezone calendar_urls days_to_show minimum_slot_minutes event_buffer availability first_day_of_week ].freeze
- EVENT_BUFFER_KEYS =
%w[before_minutes after_minutes].freeze
- WEEKDAYS =
%w[sunday monday tuesday wednesday thursday friday saturday].freeze
- ENV_REFERENCE =
/\A\$\{([A-Z][A-Z0-9_]*)\}\z/- TIME_FORMAT =
/\A(?:[01]\d|2[0-3]):[0-5]\d\z/- MAX_DAYS_TO_SHOW =
366- MAX_CALENDAR_URLS =
20
Instance Attribute Summary collapse
-
#buffer_after_minutes ⇒ Object
readonly
Returns the value of attribute buffer_after_minutes.
-
#buffer_before_minutes ⇒ Object
readonly
Returns the value of attribute buffer_before_minutes.
-
#calendar_urls ⇒ Object
readonly
Returns the value of attribute calendar_urls.
-
#days_to_show ⇒ Object
readonly
Returns the value of attribute days_to_show.
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#first_day_of_week ⇒ Object
readonly
Returns the value of attribute first_day_of_week.
-
#minimum_slot_minutes ⇒ Object
readonly
Returns the value of attribute minimum_slot_minutes.
-
#timezone ⇒ Object
readonly
Returns the value of attribute timezone.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raw, env: ENV) ⇒ Config
constructor
A new instance of Config.
- #windows_for(date) ⇒ Object
Constructor Details
#initialize(raw, env: ENV) ⇒ Config
Returns a new instance of Config.
40 41 42 43 44 45 46 47 48 |
# File 'lib/availability/config.rb', line 40 def initialize(raw, env: ENV) @raw = stringify_keys(raw) @env = env validate_known_keys(@raw, TOP_LEVEL_KEYS, 'configuration') parse_general_settings parse_buffers @availability = parse_availability @calendar_urls = parse_calendar_urls end |
Instance Attribute Details
#buffer_after_minutes ⇒ Object (readonly)
Returns the value of attribute buffer_after_minutes.
26 27 28 |
# File 'lib/availability/config.rb', line 26 def buffer_after_minutes @buffer_after_minutes end |
#buffer_before_minutes ⇒ Object (readonly)
Returns the value of attribute buffer_before_minutes.
26 27 28 |
# File 'lib/availability/config.rb', line 26 def buffer_before_minutes @buffer_before_minutes end |
#calendar_urls ⇒ Object (readonly)
Returns the value of attribute calendar_urls.
26 27 28 |
# File 'lib/availability/config.rb', line 26 def calendar_urls @calendar_urls end |
#days_to_show ⇒ Object (readonly)
Returns the value of attribute days_to_show.
26 27 28 |
# File 'lib/availability/config.rb', line 26 def days_to_show @days_to_show end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
26 27 28 |
# File 'lib/availability/config.rb', line 26 def enabled @enabled end |
#first_day_of_week ⇒ Object (readonly)
Returns the value of attribute first_day_of_week.
26 27 28 |
# File 'lib/availability/config.rb', line 26 def first_day_of_week @first_day_of_week end |
#minimum_slot_minutes ⇒ Object (readonly)
Returns the value of attribute minimum_slot_minutes.
26 27 28 |
# File 'lib/availability/config.rb', line 26 def minimum_slot_minutes @minimum_slot_minutes end |
#timezone ⇒ Object (readonly)
Returns the value of attribute timezone.
26 27 28 |
# File 'lib/availability/config.rb', line 26 def timezone @timezone end |
Class Method Details
.load(path, env: ENV) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/availability/config.rb', line 29 def self.load(path, env: ENV) raise ConfigError, "configuration file not found: #{path}" unless File.file?(path) raw = YAML.safe_load_file(path, permitted_classes: [], permitted_symbols: [], aliases: false) raise ConfigError, 'configuration root must be a mapping' unless raw.is_a?(Hash) new(raw, env: env) rescue Psych::Exception => e raise ConfigError, "invalid YAML in #{path}: #{e..lines.first.strip}" end |
Instance Method Details
#windows_for(date) ⇒ Object
50 51 52 |
# File 'lib/availability/config.rb', line 50 def windows_for(date) @availability.fetch(WEEKDAYS.fetch(date.wday), @availability.fetch('default')) end |