Class: OMF::Web::ContentProxy

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

Overview

TODO: Is this really the right description???

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

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.



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

def content_descriptor
  @content_descriptor
end

#content_urlObject (readonly)

Returns the value of attribute content_url.



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

def content_url
  @content_url
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



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

def mime_type
  @mime_type
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#repositoryObject (readonly)

Returns the value of attribute repository.



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

def repository
  @repository
end

Class Method Details

.[](key) ⇒ Object



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

def self.[](key)
  #key = Digest::MD5.hexdigest(url)
  OMF::Web::SessionStore[key, :content_proxy]
end

.create(content_descr, repo) ⇒ Object

content_descriptor: url, mime_type, name



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/omf-web/content/content_proxy.rb', line 22

def self.create(content_descr, repo)
  unless url = content_descr[:url]
    raise "Missing ':url' in content descriptor '#{content_descr.inspect}'"
  end
  key = Digest::MD5.hexdigest(url)

  if proxy = OMF::Web::SessionStore[key, :content_proxy]
    return proxy
  end
  debug "Create content proxy for '#{url}' (#{content_descr.inspect})"
  self.new(key, content_descr, repo)
end

Instance Method Details

#contentObject Also known as: read



56
57
58
59
60
61
# File 'lib/omf-web/content/content_proxy.rb', line 56

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



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/omf-web/content/content_proxy.rb', line 65

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



37
38
39
40
# File 'lib/omf-web/content/content_proxy.rb', line 37

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

#on_post(req) ⇒ Object



42
43
44
45
46
# File 'lib/omf-web/content/content_proxy.rb', line 42

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

#read_only?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/omf-web/content/content_proxy.rb', line 77

def read_only?
  @repository.read_only?
end

#to_sObject



81
82
83
# File 'lib/omf-web/content/content_proxy.rb', line 81

def to_s
  "\#<#{self.class} - #@name>"
end

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



48
49
50
51
52
53
54
# File 'lib/omf-web/content/content_proxy.rb', line 48

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