Class: OMF::Web::ContentProxy
- Inherits:
-
Base::LObject
- Object
- Base::LObject
- OMF::Web::ContentProxy
- 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
-
#content_descriptor ⇒ Object
readonly
Returns the value of attribute content_descriptor.
-
#content_url ⇒ Object
readonly
Returns the value of attribute content_url.
-
#mime_type ⇒ Object
readonly
Returns the value of attribute mime_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Class Method Summary collapse
- .[](key) ⇒ Object
-
.create(content_descr, repo) ⇒ Object
content_descriptor: url, mime_type, name.
Instance Method Summary collapse
- #content ⇒ Object (also: #read)
-
#create_proxy_for_url(url) ⇒ Object
Return a new proxy for a url relative to this one.
- #on_get(req) ⇒ Object
- #on_post(req) ⇒ Object
- #read_only? ⇒ Boolean
- #to_s ⇒ Object
- #write(content, message = "") ⇒ Object
Instance Attribute Details
#content_descriptor ⇒ Object (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_url ⇒ Object (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_type ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
35 36 37 |
# File 'lib/omf-web/content/content_proxy.rb', line 35 def name @name end |
#repository ⇒ Object (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
#content ⇒ Object 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
77 78 79 |
# File 'lib/omf-web/content/content_proxy.rb', line 77 def read_only? @repository.read_only? end |
#to_s ⇒ Object
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, = "") if content != @content debug "Updating '#{@content_descriptor.inspect}'" @content = content @repository.write(@content_descriptor, content, ) end end |