Class: OMF::Web::StaticContentRepository

Inherits:
ContentRepository show all
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

#name, #top_dir

Instance Method Summary collapse

Methods inherited from ContentRepository

#absolute_path, absolute_path_for, create_content_proxy_for, create_url, #find_files, find_files, find_repo_for, #get_url_for_path, #path, read_content, register_repo

Methods included from Common::Loggable

#_logger, #debug, #error, #fatal, #info, init_log, logger, set_environment, #warn

Constructor Details

#initialize(name, opts) ⇒ StaticContentRepository

Returns a new instance of StaticContentRepository.



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

def initialize(name, opts)
  super
  @content = {}
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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/omf-web/content/static_repository.rb', line 21

def create_content_proxy_for(content_descr)
  debug 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



49
50
51
# File 'lib/omf-web/content/static_repository.rb', line 49

def mime_type_for_file(content_descriptor)
  content_descriptor[:mime_type] || 'text'
end

#read(content_descr) ⇒ Object



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

def read(content_descr)
  debug "READ: #{content_descr}"
  @content[content_descr[:url_key]] || 'Unknown'
end

#write(content_descr, content, message) ⇒ Object



45
46
47
# File 'lib/omf-web/content/static_repository.rb', line 45

def write(content_descr, content, message)
  raise "READ ONLY"
end