Class: Adva::Static::Server::Watch

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/adva/static/server/watch.rb,
lib/adva/static/server/watch/handler.rb

Defined Under Namespace

Classes: Handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}, &block) ⇒ Watch

Returns a new instance of Watch.



15
16
17
18
19
20
# File 'lib/adva/static/server/watch.rb', line 15

def initialize(app, options = {}, &block)
  @app = app
  @dir = Pathname.new(options[:dir] || File.expand_path('import'))
  dir.mkpath
  run!
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



11
12
13
# File 'lib/adva/static/server/watch.rb', line 11

def app
  @app
end

#dirObject (readonly)

Returns the value of attribute dir.



11
12
13
# File 'lib/adva/static/server/watch.rb', line 11

def dir
  @dir
end

#watchObject (readonly)

Returns the value of attribute watch.



11
12
13
# File 'lib/adva/static/server/watch.rb', line 11

def watch
  @watch
end

Instance Method Details

#get(path) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/adva/static/server/watch.rb', line 33

def get(path)
  import  = Adva::Static::Import.new(:source => dir)
  request = import.request_for(path)
  self.request('GET', request.public_path, STORE_HEADER => true)
rescue Exception => e
  Adva.out.puts e.message
  e.backtrace.each { |line| Adva.out.puts line }
end

#update(path, event_type = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/adva/static/server/watch.rb', line 22

def update(path, event_type = nil)
  Adva.out.puts "\n#{event_type}: #{path}"
  import  = Import.new(:source => dir)
  request = import.request_for(path)
  status, headers, response = self.request('POST', request.path, request.params)
  response = get(path) if !request.destroy? && status == 302
rescue Exception => e
  Adva.out.puts e.message
  e.backtrace.each { |line| Adva.out.puts line }
end