Class: Benoit::PageMetadata::Store
- Inherits:
-
Object
- Object
- Benoit::PageMetadata::Store
- Includes:
- Singleton
- Defined in:
- lib/benoit/page_metadata/store.rb
Instance Method Summary collapse
- #[](wrapper) ⇒ Object
- #expire! ⇒ Object
- #has_page?(page_name) ⇒ Boolean
- #import_all!(hash) ⇒ Object
- #import_from_page(input) ⇒ Object
- #import_metadata(path, metadata) ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
- #path_from_key(key) ⇒ Object
- #path_to_key(path) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
13 14 15 |
# File 'lib/benoit/page_metadata/store.rb', line 13 def initialize @container = container_class.new end |
Instance Method Details
#[](wrapper) ⇒ Object
37 38 39 40 |
# File 'lib/benoit/page_metadata/store.rb', line 37 def [](wrapper) import_from_page(wrapper) unless has_page?(wrapper.path) @container[path_to_key(wrapper.path)] || {} end |
#expire! ⇒ Object
52 53 54 55 |
# File 'lib/benoit/page_metadata/store.rb', line 52 def expire! @container.clear @container = container_class.new end |
#has_page?(page_name) ⇒ Boolean
42 43 44 45 |
# File 'lib/benoit/page_metadata/store.rb', line 42 def has_page?(page_name) return unless @container @container.key?(path_to_key(page_name)) end |
#import_all!(hash) ⇒ Object
23 24 25 |
# File 'lib/benoit/page_metadata/store.rb', line 23 def import_all!(hash) @container = container_class[hash] end |
#import_from_page(input) ⇒ Object
17 18 19 20 21 |
# File 'lib/benoit/page_metadata/store.rb', line 17 def import_from_page(input) = Parser.parse(input) ["_original_path"] = input.path (input.path, ) end |
#import_metadata(path, metadata) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/benoit/page_metadata/store.rb', line 27 def (path, ) key = path_to_key(path) if @container.respond_to?(:key?) and @container.key?(key) @container[key] else @container ||= container_class.new @container[key] = end end |
#path_from_key(key) ⇒ Object
57 58 59 60 61 |
# File 'lib/benoit/page_metadata/store.rb', line 57 def path_from_key(key) key.to_s.sub /__(.+)_metadata/ do |match,blah| $1 end end |
#path_to_key(path) ⇒ Object
63 64 65 |
# File 'lib/benoit/page_metadata/store.rb', line 63 def path_to_key(path) :"__#{path}_metadata" end |
#to_hash ⇒ Object
47 48 49 50 |
# File 'lib/benoit/page_metadata/store.rb', line 47 def to_hash return unless @container @container.to_hash end |