Class: Opal::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/opal/sprockets/server.rb

Defined Under Namespace

Classes: Index

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(debug_or_options = {}) {|_self| ... } ⇒ Server

Returns a new instance of Server.

Yields:

  • (_self)

Yield Parameters:

  • _self (Opal::Server)

    the object that the method was called on



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/opal/sprockets/server.rb', line 48

def initialize debug_or_options = {}
  unless Hash === debug_or_options
    warn "passing a boolean to control debug is deprecated.\n"+
         "Please pass an Hash instead: Server.new(debug: true)"
    options = {:debug => debug_or_options}
  else
    options = debug_or_options
  end

  @public_dir = '.'
  @sprockets  = Environment.new
  @debug      = options.fetch(:debug, true)

  yield self if block_given?
  create_app
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



46
47
48
# File 'lib/opal/sprockets/server.rb', line 46

def debug
  @debug
end

#index_pathObject

Returns the value of attribute index_path.



46
47
48
# File 'lib/opal/sprockets/server.rb', line 46

def index_path
  @index_path
end

#mainObject

Returns the value of attribute main.



46
47
48
# File 'lib/opal/sprockets/server.rb', line 46

def main
  @main
end

#public_dirObject

Returns the value of attribute public_dir.



46
47
48
# File 'lib/opal/sprockets/server.rb', line 46

def public_dir
  @public_dir
end

#sprocketsObject

Returns the value of attribute sprockets.



46
47
48
# File 'lib/opal/sprockets/server.rb', line 46

def sprockets
  @sprockets
end

Instance Method Details

#append_path(path) ⇒ Object



69
70
71
# File 'lib/opal/sprockets/server.rb', line 69

def append_path path
  @sprockets.append_path path
end

#call(env) ⇒ Object



93
94
95
# File 'lib/opal/sprockets/server.rb', line 93

def call(env)
  @app.call env
end

#create_appObject



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/opal/sprockets/server.rb', line 77

def create_app
  server, sprockets = self, @sprockets

  @app = Rack::Builder.app do
    use Rack::ShowExceptions
    map('/assets') { run sprockets }
    map(server.source_maps.prefix) { run server.source_maps } if server.source_map_enabled
    use Index, server
    run Rack::Directory.new(server.public_dir)
  end
end

#source_map_enabledObject



65
66
67
# File 'lib/opal/sprockets/server.rb', line 65

def source_map_enabled
  Opal::Processor.source_map_enabled
end

#source_mapsObject



89
90
91
# File 'lib/opal/sprockets/server.rb', line 89

def source_maps
  @source_maps ||= SourceMapServer.new(@sprockets)
end

#use_gem(gem_name) ⇒ Object



73
74
75
# File 'lib/opal/sprockets/server.rb', line 73

def use_gem gem_name
  @sprockets.use_gem gem_name
end