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, #start_message_bus

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.



50
51
52
53
54
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
# File 'lib/volt/volt/app.rb', line 50

def initialize(app_path=nil)
  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

    start_message_bus
  end
end

Instance Attribute Details

#app_pathObject (readonly)

Returns the value of attribute app_path.



45
46
47
# File 'lib/volt/volt/app.rb', line 45

def app_path
  @app_path
end

#browserObject (readonly)

Returns the value of attribute browser.



45
46
47
# File 'lib/volt/volt/app.rb', line 45

def browser
  @browser
end

#channel_live_queriesObject (readonly)

Returns the value of attribute channel_live_queries.



45
46
47
# File 'lib/volt/volt/app.rb', line 45

def channel_live_queries
  @channel_live_queries
end

#component_pathsObject (readonly)

Returns the value of attribute component_paths.



45
46
47
# File 'lib/volt/volt/app.rb', line 45

def component_paths
  @component_paths
end

#databaseObject (readonly)

Returns the value of attribute database.



45
46
47
# File 'lib/volt/volt/app.rb', line 45

def database
  @database
end

#live_query_poolObject (readonly)

Returns the value of attribute live_query_pool.



45
46
47
# File 'lib/volt/volt/app.rb', line 45

def live_query_pool
  @live_query_pool
end

#message_busObject (readonly)

Returns the value of attribute message_bus.



45
46
47
# File 'lib/volt/volt/app.rb', line 45

def message_bus
  @message_bus
end

#middlewareObject (readonly)

Returns the value of attribute middleware.



45
46
47
# File 'lib/volt/volt/app.rb', line 45

def middleware
  @middleware
end

#opal_filesObject

Returns the value of attribute opal_files.



48
49
50
# File 'lib/volt/volt/app.rb', line 48

def opal_files
  @opal_files
end

#routerObject (readonly)

Returns the value of attribute router.



45
46
47
# File 'lib/volt/volt/app.rb', line 45

def router
  @router
end

#sprocketsObject

Returns the value of attribute sprockets.



48
49
50
# File 'lib/volt/volt/app.rb', line 48

def sprockets
  @sprockets
end

Instance Method Details

#add_routes(&block) ⇒ Object

Called on the client side to add routes



114
115
116
117
118
# File 'lib/volt/volt/app.rb', line 114

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



121
122
123
# File 'lib/volt/volt/app.rb', line 121

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

#channelObject



129
130
131
132
133
134
135
136
137
# File 'lib/volt/volt/app.rb', line 129

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

#setup_browserObject

Setup a Page instance.



140
141
142
# File 'lib/volt/volt/app.rb', line 140

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

#tasksObject



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

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

#templatesObject



109
110
111
# File 'lib/volt/volt/app.rb', line 109

def templates
  @templates ||= Templates.new
end