Class: CodeSync::Server
- Inherits:
-
Object
- Object
- CodeSync::Server
- Defined in:
- lib/code_sync/server.rb
Defined Under Namespace
Classes: FayeMonitor, ServerInfo, SourceProvider
Instance Attribute Summary collapse
-
#assets ⇒ Object
Returns the value of attribute assets.
-
#faye ⇒ Object
Returns the value of attribute faye.
-
#forbid_saving ⇒ Object
Returns the value of attribute forbid_saving.
-
#options ⇒ Object
Returns the value of attribute options.
-
#rack ⇒ Object
Returns the value of attribute rack.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #allow_saving? ⇒ Boolean
- #call(env) ⇒ Object
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #start(port = 9295) ⇒ Object
- #stop ⇒ Object
- #urlmap ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/code_sync/server.rb', line 21 def initialize ={} @options = .dup @assets = [:assets] || CodeSync::SprocketsAdapter.new(root:Dir.pwd()) @root = [:root] @forbid_saving = !!([:forbid_saving]) Faye::WebSocket.load_adapter('thin') @faye = Faye::RackAdapter.new(mount:"/faye",timeout:25) faye.add_extension(FayeMonitor.new) end |
Instance Attribute Details
#assets ⇒ Object
Returns the value of attribute assets.
13 14 15 |
# File 'lib/code_sync/server.rb', line 13 def assets @assets end |
#faye ⇒ Object
Returns the value of attribute faye.
13 14 15 |
# File 'lib/code_sync/server.rb', line 13 def faye @faye end |
#forbid_saving ⇒ Object
Returns the value of attribute forbid_saving.
13 14 15 |
# File 'lib/code_sync/server.rb', line 13 def forbid_saving @forbid_saving end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/code_sync/server.rb', line 13 def @options end |
#rack ⇒ Object
Returns the value of attribute rack.
13 14 15 |
# File 'lib/code_sync/server.rb', line 13 def rack @rack end |
#root ⇒ Object
Returns the value of attribute root.
13 14 15 |
# File 'lib/code_sync/server.rb', line 13 def root @root end |
Instance Method Details
#allow_saving? ⇒ Boolean
38 39 40 |
# File 'lib/code_sync/server.rb', line 38 def allow_saving? forbid_saving == true end |
#call(env) ⇒ Object
34 35 36 |
# File 'lib/code_sync/server.rb', line 34 def call(env) [200, {"Access-Control-Allow-Origin"=>"*","Content-Type" => "application/json"}, [{code_sync:true}.to_json]] end |
#start(port = 9295) ⇒ Object
49 50 51 52 |
# File 'lib/code_sync/server.rb', line 49 def start port=9295 @port = port Rack::Server.start(app:urlmap,:Port=>port,:server=>'thin',:pid => File.join("/tmp/codesync-server.pid") ) end |
#stop ⇒ Object
54 55 56 |
# File 'lib/code_sync/server.rb', line 54 def stop end |
#urlmap ⇒ Object
42 43 44 45 46 47 |
# File 'lib/code_sync/server.rb', line 42 def urlmap Rack::URLMap.new "/assets" => assets.env, "/" => faye, "/info" => ServerInfo.new(self, sprockets:assets, options: , root: root, allow_saving: allow_saving?), "/source" => SourceProvider.new(self, sprockets:assets, allow_saving: allow_saving?) end |