Class: Tlapse::Config
- Inherits:
-
Object
- Object
- Tlapse::Config
- Defined in:
- lib/tlapse/config.rb
Defined Under Namespace
Classes: Validation
Constant Summary collapse
- CONFIG_OPTIONS =
{ "lat" => { default: 35.779590, desc: "Your current latitude", type: :float }, "lon" => { default: -78.638179, desc: "Your current longitude", type: :float }, "tz" => { default: -> { Tlapse::Config.current_tz }, desc: "Your current timezone", type: :string, validations: [ Validation.new( ->(tz) { TZInfo::Timezone.get(tz) }, ->(tz) do zones = ActiveSupport::TimeZone.all.map do |tz| tz.tzinfo.name end.uniq.sort.join("\n") "#{tz} is not a valid timezone. Valid zones are:\n\n#{zones}" end ) ] } }.freeze
- CONFIG_KEYS =
CONFIG_OPTIONS.keys.freeze
- CONFIG_PATH =
File. ".config/tlapse/tlapse.yaml", Dir.home
- CONFIG_UNDEFINED =
:undefined
Class Method Summary collapse
Class Method Details
.get(*options) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tlapse/config.rb', line 50 def self.get(*) values = Array().map do |option| verify_option_exists! option value = value_for option value == CONFIG_UNDEFINED ? default_for(option) : value end values.length == 1 ? values.first : values end |
.list ⇒ Object
46 47 48 |
# File 'lib/tlapse/config.rb', line 46 def self.list CONFIG_OPTIONS end |
.set(option, value) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tlapse/config.rb', line 61 def self.set(option, value) verify_option_exists! option validate! option, value values = user_values if value == default_for(option) values.delete option else values[option] = value end save values end |
.unset(option) ⇒ Object
76 77 78 |
# File 'lib/tlapse/config.rb', line 76 def self.unset(option) set option, default_for(option) end |