Class: Almanack::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/almanack/configuration.rb

Defined Under Namespace

Classes: ThemeNotFound

Constant Summary collapse

CACHE_DIR =
"tmp"
DEFAULT_THEME =
"legacy"
DEFAULT_DAYS_LOOKAHEAD =
30
DEFAULT_FEED_LOOKAHEAD =
365
DEFAULT_CACHE_RESPONSES =
false
DEFAULT_CACHE_EXPIRY =
900

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



22
23
24
# File 'lib/almanack/configuration.rb', line 22

def initialize
  reset!
end

Instance Attribute Details

#cache_expiryObject

Returns the value of attribute cache_expiry.



13
14
15
# File 'lib/almanack/configuration.rb', line 13

def cache_expiry
  @cache_expiry
end

#cache_responsesObject

Returns the value of attribute cache_responses.



13
14
15
# File 'lib/almanack/configuration.rb', line 13

def cache_responses
  @cache_responses
end

#days_lookaheadObject

Returns the value of attribute days_lookahead.



13
14
15
# File 'lib/almanack/configuration.rb', line 13

def days_lookahead
  @days_lookahead
end

#event_sourcesObject (readonly)

Returns the value of attribute event_sources.



12
13
14
# File 'lib/almanack/configuration.rb', line 12

def event_sources
  @event_sources
end

#feed_lookaheadObject

Returns the value of attribute feed_lookahead.



13
14
15
# File 'lib/almanack/configuration.rb', line 13

def feed_lookahead
  @feed_lookahead
end

#themeObject

Returns the value of attribute theme.



13
14
15
# File 'lib/almanack/configuration.rb', line 13

def theme
  @theme
end

#theme_pathsObject

Returns the value of attribute theme_paths.



13
14
15
# File 'lib/almanack/configuration.rb', line 13

def theme_paths
  @theme_paths
end

#theme_rootObject

Returns the value of attribute theme_root.



13
14
15
# File 'lib/almanack/configuration.rb', line 13

def theme_root
  @theme_root
end

#titleObject

Returns the value of attribute title.



13
14
15
# File 'lib/almanack/configuration.rb', line 13

def title
  @title
end

Instance Method Details

#add_event_source(source) ⇒ Object



53
54
55
# File 'lib/almanack/configuration.rb', line 53

def add_event_source(source)
  @event_sources << source
end

#add_events(events) ⇒ Object



65
66
67
# File 'lib/almanack/configuration.rb', line 65

def add_events(events)
  add_event_source EventSource::Static.new(events)
end

#add_ical(io) ⇒ Object



61
62
63
# File 'lib/almanack/configuration.rb', line 61

def add_ical(io)
  add_event_source EventSource::Ical.from(io)
end

#add_ical_feed(url) ⇒ Object



57
58
59
# File 'lib/almanack/configuration.rb', line 57

def add_ical_feed(url)
  add_event_source EventSource::IcalFeed.new(url, connection: connection)
end

#add_meetup_group(options) ⇒ Object



69
70
71
# File 'lib/almanack/configuration.rb', line 69

def add_meetup_group(options)
  fail "Unfortunately, due to Meetup's changes to their API, this integration is no longer supported. See https://github.com/Aupajo/almanack/issues/36 for more information."
end

#cache_storeObject



73
74
75
# File 'lib/almanack/configuration.rb', line 73

def cache_store
  @cache_store ||= ActiveSupport::Cache::FileStore.new(cache_dir, expires_in: cache_expiry)
end

#connectionObject



26
27
28
29
30
31
# File 'lib/almanack/configuration.rb', line 26

def connection
  @connection ||= Faraday.new do |conn|
    conn.response(:caching) { cache_store } if cache_responses
    conn.adapter Faraday.default_adapter
  end
end

#reset!Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/almanack/configuration.rb', line 33

def reset!
  @theme           = DEFAULT_THEME
  @days_lookahead  = DEFAULT_DAYS_LOOKAHEAD
  @feed_lookahead  = DEFAULT_FEED_LOOKAHEAD
  @event_sources   = []
  @cache_responses = DEFAULT_CACHE_RESPONSES
  @cache_expiry    = DEFAULT_CACHE_EXPIRY

  @theme_paths = [
    Pathname.pwd.join('themes'),
    Pathname(__dir__).join('themes')
  ]
end