Class: RhetButler::Web::MainApp

Inherits:
Object
  • Object
show all
Defined in:
lib/rhet-butler/web/main-app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_manager) ⇒ MainApp

Returns a new instance of MainApp.



30
31
32
33
# File 'lib/rhet-butler/web/main-app.rb', line 30

def initialize(file_manager)
  @file_manager = file_manager
  @capture_exceptions = true
end

Instance Attribute Details

#assets_app_classObject

Returns the value of attribute assets_app_class.



35
36
37
# File 'lib/rhet-butler/web/main-app.rb', line 35

def assets_app_class
  @assets_app_class
end

#capture_exceptionsObject

Returns the value of attribute capture_exceptions.



36
37
38
# File 'lib/rhet-butler/web/main-app.rb', line 36

def capture_exceptions
  @capture_exceptions
end

#presentation_app_classObject

Returns the value of attribute presentation_app_class.



35
36
37
# File 'lib/rhet-butler/web/main-app.rb', line 35

def presentation_app_class
  @presentation_app_class
end

Instance Method Details

#build_authentication_block(creds_config) ⇒ Object



71
72
73
74
75
76
# File 'lib/rhet-butler/web/main-app.rb', line 71

def build_authentication_block(creds_config)
  return (proc do |user, pass|
    creds_config.username == user &&
      creds_config.password == pass
  end)
end

#build_serverObject



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/rhet-butler/web/main-app.rb', line 130

def build_server
  configuration = @file_manager.base_config

  Thin::Logging.log_info "Starting server. Try one of these:"
  require 'system/getifaddrs'
  System.get_all_ifaddrs.each do |interface|
    Thin::Logging.log_info "  http://#{interface[:inet_addr].to_s}:#{configuration.serve_port}/"
    Thin::Logging.log_info "  http://#{interface[:inet_addr].to_s}:#{configuration.serve_port}/qr"
  end
  server = Thin::Server.new(builder.to_app, configuration.serve_port)
  server.threaded = true
  server
end

#builderObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rhet-butler/web/main-app.rb', line 78

def builder
  sockjs_options = {
    :sockjs_url => "/assets/javascript/sockjs-0.3.4.js",
    :queue => SlideMessageQueue.new
  }

  viewer_app = self.viewer_app
  presenter_app = presentation_app_class.new(:presenter, @file_manager)
  assets_app = assets_app_class.new(@file_manager)
  qr_app = QrDisplayApp.new(@file_manager, "/presenter")
  presenter_config = presenter_app.configuration
  auth_validation = build_authentication_block(presenter_config)

  Rack::Builder.new do
    #SockJS.debug!

    map "/live/follower" do
      run Rack::SockJS.new(FollowerSession, sockjs_options)
    end

    map "/live/leader" do
      use SelectiveAuth, "Rhet Butler Presenter", &auth_validation
      run Rack::SockJS.new(LeaderSession, sockjs_options)
    end

    if @capture_exceptions
      use Rack::ShowExceptions
    end

    map "/assets" do
      run assets_app
    end

    map "/qr" do
      run qr_app
    end

    map "/presenter" do
      use SelectiveAuth, "Rhet Butler Presenter", &auth_validation
      run presenter_app
    end

    run lambda{|env|
      if env["PATH_INFO"] == "/"
        viewer_app.call(env)
      else
        assets_app.call(env)
      end
    }
  end
end

#checkObject

Simply renders the bodies of the viewer and presenter apps to make sure there aren’t any exceptions



63
64
65
66
67
68
69
# File 'lib/rhet-butler/web/main-app.rb', line 63

def check
  presenter_app = presentation_app_class.new(:presenter, @file_manager)
  viewer_app.body
  presenter_app.body
  #XXX static generator "populate assets" - make sure all the assets
  #render as well
end

#slidesObject

Notes re filesets config and slides: All PresentationApps need the same slides but different configs (including templates, etc.)

So: there need to be TWO valises:

1) The slides valise - including slidesets that might get included - this one is common between all Apps

2) The config valise - there should be a “common” base to this, and a role specific variation. Built special, because the /viewer app should allow for config in the root of the project etc, while the /presenter version should require special config (since I’m assuming a boring presentation view)



53
54
55
# File 'lib/rhet-butler/web/main-app.rb', line 53

def slides
  @file_manager.slide_files
end

#startObject

:nocov:



145
146
147
# File 'lib/rhet-butler/web/main-app.rb', line 145

def start
  build_server.start
end

#viewer_appObject



57
58
59
# File 'lib/rhet-butler/web/main-app.rb', line 57

def viewer_app
  @viewer_app ||= presentation_app_class.new(:viewer, @file_manager)
end