Class: CodeSync::Server

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

Defined Under Namespace

Classes: FayeMonitor, ServerInfo, SourceProvider

Instance Attribute Summary collapse

Instance Method Summary collapse

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={}
  @options        = options.dup
  @assets         = options[:assets] || CodeSync::SprocketsAdapter.new(root:Dir.pwd())
  @root           = options[:root]
  @forbid_saving  = !!(options[:forbid_saving])

  Faye::WebSocket.load_adapter('thin')

  @faye   = Faye::RackAdapter.new(mount:"/faye",timeout:25)

  faye.add_extension(FayeMonitor.new)
end

Instance Attribute Details

#assetsObject

Returns the value of attribute assets.



13
14
15
# File 'lib/code_sync/server.rb', line 13

def assets
  @assets
end

#fayeObject

Returns the value of attribute faye.



13
14
15
# File 'lib/code_sync/server.rb', line 13

def faye
  @faye
end

#forbid_savingObject

Returns the value of attribute forbid_saving.



13
14
15
# File 'lib/code_sync/server.rb', line 13

def forbid_saving
  @forbid_saving
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/code_sync/server.rb', line 13

def options
  @options
end

#rackObject

Returns the value of attribute rack.



13
14
15
# File 'lib/code_sync/server.rb', line 13

def rack
  @rack
end

#rootObject

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

Returns:

  • (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

#stopObject



54
55
56
# File 'lib/code_sync/server.rb', line 54

def stop

end

#urlmapObject



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: options, root: root, allow_saving: allow_saving?),
                     "/source" =>   SourceProvider.new(self, sprockets:assets, allow_saving: allow_saving?)
end