Class: Marsdawn::Storage::ActiveRecord
- Defined in:
- lib/marsdawn/storage/active_record.rb
Defined Under Namespace
Classes: Marsdawn
Instance Method Summary collapse
- #clean_up ⇒ Object
- #finalize ⇒ Object
- #get(uri) ⇒ Object
- #get_document_info ⇒ Object
-
#initialize(config, opts = {}) ⇒ ActiveRecord
constructor
A new instance of ActiveRecord.
- #prepare ⇒ Object
- #set(uri, content, front_matter, sysinfo) ⇒ Object
- #set_document_info(doc_info) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(config, opts = {}) ⇒ ActiveRecord
Returns a new instance of ActiveRecord.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/marsdawn/storage/active_record.rb', line 9 def initialize config, opts={} unless Module.const_defined?('ActiveRecord') raise "Gem 'active_record' should be installed to use ActiveRecord storage for MarsDawn." unless require 'active_record' end #require 'marsdawn/storage/active_record/marsdawn' @opts = { key: '-', lang: 'en', version: '0.0.1' }.merge(opts) end |
Instance Method Details
#clean_up ⇒ Object
44 45 46 |
# File 'lib/marsdawn/storage/active_record.rb', line 44 def clean_up @stack = {} end |
#finalize ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/marsdawn/storage/active_record.rb', line 26 def finalize MarsdawnDocs.transaction do MarsdawnDocs.where(selector).each do |page| MarsdawnDocs.delete_all(selector(uri: page.uri)) unless @stack.key?(page.uri) end @stack.each do |uri, data| rec = MarsdawnDocs.where(selector(uri: uri)) if rec.size > 0 rec.first.update_attributes! data: compress(data) else MarsdawnDocs.create selector(uri: uri, data: compress(data)) end end end rescue => e raise e end |
#get(uri) ⇒ Object
60 61 62 63 |
# File 'lib/marsdawn/storage/active_record.rb', line 60 def get uri data = get_data(uri) Marsdawn::Util.hash_symbolize_keys_deep(data) unless data.nil? end |
#get_document_info ⇒ Object
56 57 58 |
# File 'lib/marsdawn/storage/active_record.rb', line 56 def get_document_info Marsdawn::Util.hash_symbolize_keys(get_data('doc_info')) end |
#prepare ⇒ Object
21 22 23 24 |
# File 'lib/marsdawn/storage/active_record.rb', line 21 def prepare #Marsdawn.create_unless_exists @stack = {} end |
#set(uri, content, front_matter, sysinfo) ⇒ Object
52 53 54 |
# File 'lib/marsdawn/storage/active_record.rb', line 52 def set uri, content, front_matter, sysinfo @stack[uri] = {content: content, front_matter: front_matter, sysinfo: sysinfo} end |
#set_document_info(doc_info) ⇒ Object
48 49 50 |
# File 'lib/marsdawn/storage/active_record.rb', line 48 def set_document_info doc_info @stack['doc_info'] = doc_info end |