Class: Volt::App

Inherits:
Object show all
Includes:
Repos, ServerSetup::App
Defined in:
lib/volt/volt/app.rb

Instance Attribute Summary collapse

Attributes included from ServerSetup::App

#app_url, #root_url

Instance Method Summary collapse

Methods included from ServerSetup::App

#load_app_code, #require_components, #require_http_controllers, #reset_query_pool!, #run_app_and_initializers, #run_config, #setup_paths, #setup_postboot_middleware, #setup_preboot_middleware, #setup_router, #setup_routes, #start_message_bus

Methods included from Eventable

#on, #remove_listener, #trigger!

Methods included from Repos

#check_for_client?, #cookies, #flash, #local_store, #page, #params, #store, #url

Constructor Details

#initialize(app_path = nil) ⇒ App

Returns a new instance of App.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
# File 'lib/volt/volt/app.rb', line 55

def initialize(app_path=nil)
  app_path ||= Dir.pwd

  if Volt.server? && !app_path
    raise "Volt::App.new requires an app path to boot"
  end

  # Expand to a full path
  app_path = File.expand_path(app_path)

  @app_path = app_path
  $volt_app = self

  # Setup root path
  Volt.root = app_path

  if RUBY_PLATFORM == 'opal'
    setup_browser
  end

  if RUBY_PLATFORM != 'opal'
    # We need to run the root config first so we can setup the Rack::Session
    # middleware.
    run_config

    # Setup all of the middleware we can before we load the users components
    # since the users components might want to add middleware during boot.
    setup_preboot_middleware

    # Setup all app paths
    setup_paths

    # Require in app and initializers
    run_app_and_initializers unless RUBY_PLATFORM == 'opal'

    require_components

    # abort_on_exception is a useful debugging tool, and in my opinion something
    # you probbaly want on.  That said you can disable it if you need.
    unless RUBY_PLATFORM == 'opal'
      Thread.abort_on_exception = Volt.config.abort_on_exception
    end

    load_app_code

    # Load up the main component dependencies.  This is needed to load in
    # any opal_gem calls in dependencies.rb
    # TODO: Needs to support all components
    if Dir.exists?(Volt.root + '/app/main')
      AssetFiles.from_cache(app_url, 'main', component_paths)
    end

    reset_query_pool!

    # Setup the middleware that we can only setup after all components boot.
    setup_postboot_middleware

    setup_routes

    start_message_bus
  end
end

Instance Attribute Details

#app_pathObject (readonly)

Returns the value of attribute app_path.



50
51
52
# File 'lib/volt/volt/app.rb', line 50

def app_path
  @app_path
end

#browserObject (readonly)

Returns the value of attribute browser.



50
51
52
# File 'lib/volt/volt/app.rb', line 50

def browser
  @browser
end

#channel_live_queriesObject (readonly)

Returns the value of attribute channel_live_queries.



50
51
52
# File 'lib/volt/volt/app.rb', line 50

def channel_live_queries
  @channel_live_queries
end

#component_pathsObject (readonly)

Returns the value of attribute component_paths.



50
51
52
# File 'lib/volt/volt/app.rb', line 50

def component_paths
  @component_paths
end

#databaseObject (readonly)

Returns the value of attribute database.



50
51
52
# File 'lib/volt/volt/app.rb', line 50

def database
  @database
end

#live_query_poolObject (readonly)

Returns the value of attribute live_query_pool.



50
51
52
# File 'lib/volt/volt/app.rb', line 50

def live_query_pool
  @live_query_pool
end

#message_busObject (readonly)

Returns the value of attribute message_bus.



50
51
52
# File 'lib/volt/volt/app.rb', line 50

def message_bus
  @message_bus
end

#middlewareObject (readonly)

Returns the value of attribute middleware.



50
51
52
# File 'lib/volt/volt/app.rb', line 50

def middleware
  @middleware
end

#opal_filesObject

Returns the value of attribute opal_files.



53
54
55
# File 'lib/volt/volt/app.rb', line 53

def opal_files
  @opal_files
end

#routerObject (readonly)

Returns the value of attribute router.



50
51
52
# File 'lib/volt/volt/app.rb', line 50

def router
  @router
end

#sprocketsObject

Returns the value of attribute sprockets.



53
54
55
# File 'lib/volt/volt/app.rb', line 53

def sprockets
  @sprockets
end

Instance Method Details

#add_routes(&block) ⇒ Object

Called on the client side to add routes



123
124
125
126
127
# File 'lib/volt/volt/app.rb', line 123

def add_routes(&block)
  @router ||= Routes.new
  @router.define(&block)
  url.router = @router
end

#add_template(*args) ⇒ Object

Callled on the client to add store compiled templates



130
131
132
# File 'lib/volt/volt/app.rb', line 130

def add_template(*args)
  templates.add_template(*args)
end

#channelObject



138
139
140
141
142
143
144
145
146
# File 'lib/volt/volt/app.rb', line 138

def channel
  @channel ||= begin
    if Volt.client?
      Channel.new
    else
      ChannelStub.new
    end
  end
end

#setup_browserObject

Setup a Page instance.



149
150
151
# File 'lib/volt/volt/app.rb', line 149

def setup_browser
  @browser = Browser.new(self)
end

#tasksObject



134
135
136
# File 'lib/volt/volt/app.rb', line 134

def tasks
  @tasks ||= Tasks.new(self)
end

#templatesObject



118
119
120
# File 'lib/volt/volt/app.rb', line 118

def templates
  @templates ||= Templates.new
end