Class: OMF::Web::ContentProxy

Inherits:
Base::LObject
  • Object
show all
Defined in:
lib/omf-web/content/content_proxy.rb

Overview

This object maintains synchronization between a JS DataSource object in a web browser and the corresponding OmlTable in this server.

Constant Summary collapse

@@proxies =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_descriptorObject (readonly)

Returns the value of attribute content_descriptor.



31
32
33
# File 'lib/omf-web/content/content_proxy.rb', line 31

def content_descriptor
  @content_descriptor
end

#content_idObject (readonly)

Returns the value of attribute content_id.



31
32
33
# File 'lib/omf-web/content/content_proxy.rb', line 31

def content_id
  @content_id
end

#content_urlObject (readonly)

Returns the value of attribute content_url.



31
32
33
# File 'lib/omf-web/content/content_proxy.rb', line 31

def content_url
  @content_url
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



31
32
33
# File 'lib/omf-web/content/content_proxy.rb', line 31

def mime_type
  @mime_type
end

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/omf-web/content/content_proxy.rb', line 31

def name
  @name
end

#repositoryObject (readonly)

Returns the value of attribute repository.



31
32
33
# File 'lib/omf-web/content/content_proxy.rb', line 31

def repository
  @repository
end

Class Method Details

.[](url) ⇒ Object



16
17
18
# File 'lib/omf-web/content/content_proxy.rb', line 16

def self.[](url)
  @@proxies[url.to_s]
end

.create(content_descr, repo) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/omf-web/content/content_proxy.rb', line 20

def self.create(content_descr, repo)
  unless key = content_descr[:url_key]
    raise "Missing ':url_key' in content descriptor '#{content_descr.inspect}'"
  end
  if proxy = @@proxies[key]
    return proxy
  end
  debug "Create content proxy for '#{key}' (#{content_descr.inspect})"
  @@proxies[key] = self.new(content_descr, repo)
end

Instance Method Details

#contentObject Also known as: read



53
54
55
56
57
58
# File 'lib/omf-web/content/content_proxy.rb', line 53

def content()
  unless @content
    @content = @repository.read(@content_descriptor)
  end
  @content
end

#create_proxy_for_url(url) ⇒ Object

Return a new proxy for a url relative to this one



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/omf-web/content/content_proxy.rb', line 62

def create_proxy_for_url(url)
  unless url.match ':'
    unless url.start_with? '/'
      # relative
      ap = @repository.path(@content_descriptor)
      url = File.join(File.dirname(ap), url)
    end
    url = @repository.get_url_for_path(url)
  end
  @repository.create_content_proxy_for(url)
end

#on_get(req) ⇒ Object



34
35
36
37
# File 'lib/omf-web/content/content_proxy.rb', line 34

def on_get(req)
  c = content()
  [c.to_s, "text"]
end

#on_post(req) ⇒ Object



39
40
41
42
43
# File 'lib/omf-web/content/content_proxy.rb', line 39

def on_post(req)
  data = req.POST
  write(data['content'], data['message'])
  [true.to_json, "text/json"]
end

#write(content, message = "") ⇒ Object



45
46
47
48
49
50
51
# File 'lib/omf-web/content/content_proxy.rb', line 45

def write(content, message = "")
  if content != @content
    debug "Updating '#{@content_descriptor.inspect}'"
    @content = content
    @repository.write(@content_descriptor, content, message)
  end
end