Class: CalendarAssistant::Config
- Inherits:
-
Object
- Object
- CalendarAssistant::Config
show all
- Defined in:
- lib/calendar_assistant/config.rb,
lib/calendar_assistant/config/token_store.rb
Defined Under Namespace
Modules: Keys
Classes: AccessingHashAsScalar, NoTokensAuthorized, TokenStore
Constant Summary
collapse
- DEFAULT_CALENDAR_ID =
"primary"
- DEFAULT_SETTINGS =
{
Keys::Settings::LOCATION_ICON => "🌎", Keys::Settings::MEETING_LENGTH => "30m", Keys::Settings::START_OF_DAY => "9am", Keys::Settings::END_OF_DAY => "6pm", Keys::Options::CALENDARS => [DEFAULT_CALENDAR_ID], Keys::Options::FORMATTING => true, }
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options: {}, user_config: {}, defaults: DEFAULT_SETTINGS) ⇒ Config
Returns a new instance of Config.
61
62
63
64
65
66
67
|
# File 'lib/calendar_assistant/config.rb', line 61
def initialize(options: {},
user_config: {},
defaults: DEFAULT_SETTINGS)
@defaults = defaults
@options = options
@user_config = user_config
end
|
Instance Attribute Details
#defaults ⇒ Object
Returns the value of attribute defaults.
59
60
61
|
# File 'lib/calendar_assistant/config.rb', line 59
def defaults
@defaults
end
|
#options ⇒ Object
Returns the value of attribute options.
59
60
61
|
# File 'lib/calendar_assistant/config.rb', line 59
def options
@options
end
|
#user_config ⇒ Object
Returns the value of attribute user_config.
59
60
61
|
# File 'lib/calendar_assistant/config.rb', line 59
def user_config
@user_config
end
|
Instance Method Details
#calendar_ids ⇒ Object
helper method for Keys::Options::CALENDARS
151
152
153
|
# File 'lib/calendar_assistant/config.rb', line 151
def calendar_ids
split_if_array(Keys::Options::CALENDARS)
end
|
#debug? ⇒ Boolean
163
164
165
|
# File 'lib/calendar_assistant/config.rb', line 163
def debug?
setting(Keys::Options::DEBUG)
end
|
#event_visibility ⇒ Object
#get(keypath) ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'lib/calendar_assistant/config.rb', line 101
def get(keypath)
rval = Config.find_in_hash(user_config, keypath)
if rval.is_a?(Hash)
raise CalendarAssistant::Config::AccessingHashAsScalar, "keypath #{keypath} is not a scalar"
end
rval
end
|
#in_env(&block) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/calendar_assistant/config.rb', line 69
def in_env(&block)
orig_b_o_d = BusinessTime::Config.beginning_of_workday
orig_e_o_d = BusinessTime::Config.end_of_workday
begin
BusinessTime::Config.beginning_of_workday = setting(Config::Keys::Settings::START_OF_DAY)
BusinessTime::Config.end_of_workday = setting(Config::Keys::Settings::END_OF_DAY)
yield
ensure
BusinessTime::Config.beginning_of_workday = orig_b_o_d
BusinessTime::Config.end_of_workday = orig_e_o_d
end
end
|
#must_be ⇒ Object
155
156
157
|
# File 'lib/calendar_assistant/config.rb', line 155
def must_be
split_if_array(Keys::Options::MUST_BE)
end
|
#must_not_be ⇒ Object
159
160
161
|
# File 'lib/calendar_assistant/config.rb', line 159
def must_not_be
split_if_array(Keys::Options::MUST_NOT_BE)
end
|
#persist! ⇒ Object
167
168
169
|
# File 'lib/calendar_assistant/config.rb', line 167
def persist!
end
|
#set(keypath, value) ⇒ Object
111
112
113
|
# File 'lib/calendar_assistant/config.rb', line 111
def set(keypath, value)
Config.set_in_hash user_config, keypath, value
end
|
#setting(setting_name) ⇒ Object
Also known as:
[]
note that, despite the name, this method returns both options
and settings
119
120
121
122
123
124
125
|
# File 'lib/calendar_assistant/config.rb', line 119
def setting(setting_name)
context = Config.find_in_hash(options, Keys::Options::CONTEXT)
Config.find_in_hash(options, setting_name) ||
Config.find_in_hash(user_config, [Keys::SETTINGS, context, setting_name]) ||
Config.find_in_hash(user_config, [Keys::SETTINGS, setting_name]) ||
Config.find_in_hash(defaults, setting_name)
end
|
#tokens ⇒ Object
139
140
141
142
|
# File 'lib/calendar_assistant/config.rb', line 139
def tokens
Config.find_in_hash(user_config, Keys::TOKENS) ||
Config.set_in_hash(user_config, Keys::TOKENS, {})
end
|