Class: Adalog::Web

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/adalog/web.rb

Defined Under Namespace

Classes: Config

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, web_options = {}) ⇒ Web

Returns a new instance of Web.



9
10
11
12
13
14
15
# File 'lib/adalog/web.rb', line 9

def initialize(app = nil, web_options = {})
  super(app)
  options = default_options.merge(web_options)
  @config = Adalog::Web::Config.new
  determine_config_settings(config, options)
  sinatra_class_option_overrides(options)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/adalog/web.rb', line 7

def config
  @config
end

Instance Method Details

#/Object

The primary page that matters in this simple little log.



72
73
74
75
# File 'lib/adalog/web.rb', line 72

get '/' do
  @entries = config.repo.all
  erb :'index.html'
end

#default_optionsObject



35
36
37
# File 'lib/adalog/web.rb', line 35

def default_options
  Adalog.configuration.web_defaults
end

#determine_config_settings(config, options) ⇒ Object



18
19
20
21
22
# File 'lib/adalog/web.rb', line 18

def determine_config_settings(config, options)
  config.repo         = options.fetch(:repo)
  config.heading      = options.fetch(:heading)
  config.time_format  = options.fetch(:time_format)
end

#sinatra_class_option_overrides(options) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/adalog/web.rb', line 25

def sinatra_class_option_overrides(options)
  if options.key?(:erb_layout)
    class_exec { set :erb, layout: options[:erb_layout] }
  end
  if options.key?(:views_folder)
    class_exec { set :views, options[:views_folder] }
  end
end