Class: Volt

Inherits:
Object show all
Defined in:
lib/volt/config.rb,
lib/volt.rb,
lib/volt/boot.rb,
lib/volt/spec/setup.rb,
lib/volt/volt/environment.rb,
lib/volt/data_stores/data_store.rb,
lib/volt/data_stores/mongo_driver.rb,
app/volt/controllers/notices_controller.rb

Overview

Config lets a user set global config options for Volt.

Defined Under Namespace

Classes: DataStore, Environment, NoticesController

Constant Summary collapse

@@in_browser =
false

Class Method Summary collapse

Class Method Details

.boot(app_path) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/volt/boot.rb', line 10

def self.boot(app_path)
  # Run the app config to load all users config files
  Volt.run_files_in_config_folder

  component_paths = ComponentPaths.new(app_path)
  component_paths.require_in_components

  return component_paths
end

.client?Boolean

Returns:



30
31
32
# File 'lib/volt.rb', line 30

def self.client?
  !ENV['SERVER']
end

.configObject



8
9
10
# File 'lib/volt/config.rb', line 8

def self.config
  @config || self.reset_config!
end

.envObject



38
39
40
# File 'lib/volt.rb', line 38

def self.env
  @env ||= Volt::Environment.new
end

.in_browser?Boolean

Returns:



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

def self.in_browser?
  @@in_browser
end

.loggerObject



42
43
44
# File 'lib/volt.rb', line 42

def self.logger
  @logger ||= Logger.new
end

.logger=(val) ⇒ Object



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

def self.logger=(val)
  @logger = val
end

.reset_config!Object

Resets the configuration to the default (empty hash)



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/volt/config.rb', line 13

def self.reset_config!
  app_name = File.basename(Dir.pwd)

  @config = OpenStruct.new({
    app_name: app_name,
    db_name: ENV['DB_NAME'] || (app_name + '_' + Volt.env.to_s),
    db_host: ENV['DB_HOST'] || 'localhost',
    db_port: (ENV['DB_PORT'] || 27017).to_i,
    db_driver: ENV['DB_DRIVER'] || 'mongo'
  })
end

.rootObject



18
19
20
# File 'lib/volt.rb', line 18

def self.root
  @root ||= File.expand_path(Dir.pwd)
end

.root=(val) ⇒ Object



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

def self.root=(val)
  @root = val
end

.run_files_in_config_folderObject

Load in all .rb files in the config folder



26
27
28
29
30
# File 'lib/volt/config.rb', line 26

def self.run_files_in_config_folder
  Dir[Dir.pwd + '/config/*.rb'].each do |config_file|
    require(config_file)
  end
end

.server?Boolean

Returns:



26
27
28
# File 'lib/volt.rb', line 26

def self.server?
  !!ENV['SERVER']
end

.setup {|self.config| ... } ⇒ Object

Yields:



4
5
6
# File 'lib/volt/config.rb', line 4

def self.setup
  yield self.config
end

.source_maps?Boolean

Returns:



34
35
36
# File 'lib/volt.rb', line 34

def self.source_maps?
  !!ENV['MAPS']
end

.spec_setup(app_path = '.') ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/volt/spec/setup.rb', line 2

def self.spec_setup(app_path='.')
  if RUBY_PLATFORM == 'opal'
    require 'volt'
  else
    ENV['SERVER'] = 'true'

    if ENV['BROWSER']
      require 'capybara'
      require 'capybara/dsl'
      require 'capybara/rspec'
      require 'capybara/poltergeist'
    end

    require 'volt'
    require 'volt/boot'

    # Require in app
    Volt.boot(Dir.pwd)

    if ENV['BROWSER']
      require 'volt/server'

      Capybara.server do |app, port|
        require 'rack/handler/thin'
        Rack::Handler::Thin.run(app, :Port => port)
      end

      Capybara.app = Server.new(app_path).app

      if ENV['BROWSER'] == 'phantom'
        Capybara.default_driver = :poltergeist
      elsif ENV['BROWSER'] == 'chrome'
        Capybara.register_driver :chrome do |app|
          Capybara::Selenium::Driver.new(app, :browser => :chrome)
        end

        Capybara.default_driver = :chrome
      elsif ENV['BROWSER'] == 'firefox'

        # require 'selenium/webdriver'
        # # require 'selenium/client'
        #
        Capybara.default_driver = :selenium

        # Capybara.register_driver :selenium_firefox do |app|
        #   Capybara::Selenium::Driver.new(app, :browser => :firefox)
        # end
        # Capybara.current_driver = :selenium_firefox
      elsif ENV['BROWSER'] == 'safari'
        # Needs extension
        Capybara.register_driver :safari do |app|
          Capybara::Selenium::Driver.new(app, :browser => :safari)
        end
        Capybara.default_driver = :safari
      end
    end
  end
end