Class: OMF::Web::StaticContentRepository
- Inherits:
-
ContentRepository
- Object
- Base::LObject
- ContentRepository
- OMF::Web::StaticContentRepository
- Defined in:
- lib/omf-web/content/static_repository.rb
Overview
This class provides an interface to a repository of static, preloaded content.
Constant Summary
Constants inherited from ContentRepository
ContentRepository::MIME_TYPE, ContentRepository::REPO_PLUGINS
Instance Attribute Summary
Attributes inherited from ContentRepository
Class Method Summary collapse
-
.create_from_text(descr, opts) ⇒ Object
Create a static repo.
Instance Method Summary collapse
-
#create_content_proxy_for(content_descr) ⇒ Object
Load content described by either a hash or a straightforward path and return a ‘ContentProxy’ holding it.
-
#initialize(name, opts) ⇒ StaticContentRepository
constructor
A new instance of StaticContentRepository.
- #mime_type_for_file(content_descriptor) ⇒ Object
- #read(content_descr) ⇒ Object
- #write(content_descr, content, message) ⇒ Object
Methods inherited from ContentRepository
#_get_path, #absolute_path, absolute_path_for, create, create_content_proxy_for, create_url, #exist?, find_files, #find_files, find_repo_for, #get_url_for_path, #path, read_content, #read_only?, reference_dir, reference_dir=, register_mime_type, register_repo, #to_s
Constructor Details
#initialize(name, opts) ⇒ StaticContentRepository
Returns a new instance of StaticContentRepository.
67 68 69 70 |
# File 'lib/omf-web/content/static_repository.rb', line 67 def initialize(name, opts) super @content = {} end |
Class Method Details
.create_from_text(descr, opts) ⇒ Object
Create a static repo.
@param descr - {text: ....}
@param opts - ???
@returns url for repo
20 21 22 23 24 25 26 27 28 |
# File 'lib/omf-web/content/static_repository.rb', line 20 def self.create_from_text(descr, opts) #puts "STATIC>>> #{opts}" unless (text = descr[:text]) text "Missing 'text' declaration in 'content'" end key = Digest::MD5.hexdigest(text) ContentRepository.register_repo(key, type: :static, text: text) "static:#{key}" end |
Instance Method Details
#create_content_proxy_for(content_descr) ⇒ Object
Load content described by either a hash or a straightforward path and return a ‘ContentProxy’ holding it.
@return: Content proxy
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/omf-web/content/static_repository.rb', line 35 def create_content_proxy_for(content_descr) debug "CREATE CONTENT PROXY: #{content_descr}" if content_descr.is_a? String content_descr = {text: content_descr} end descr = content_descr.dup unless text = descr.delete(:text) raise "Missing ':text' declaraton for static content" end key = Digest::MD5.hexdigest(text) @content[key] = text descr[:url] = url = "static:" + key descr[:url_key] = key descr[:name] = content_descr[:name] || url # Should be something human digestable proxy = ContentProxy.create(descr, self) return proxy end |
#mime_type_for_file(content_descriptor) ⇒ Object
63 64 65 |
# File 'lib/omf-web/content/static_repository.rb', line 63 def mime_type_for_file(content_descriptor) content_descriptor[:mime_type] || 'text' end |
#read(content_descr) ⇒ Object
54 55 56 57 |
# File 'lib/omf-web/content/static_repository.rb', line 54 def read(content_descr) debug "READ: #{content_descr}" @content[content_descr[:url_key]] || 'Unknown' end |
#write(content_descr, content, message) ⇒ Object
59 60 61 |
# File 'lib/omf-web/content/static_repository.rb', line 59 def write(content_descr, content, ) raise ReadOnlyContentRepositoryException.new end |