Class: TDiary::IO::PStore
- Inherits:
-
Object
- Object
- TDiary::IO::PStore
- Defined in:
- lib/tdiary/io/pstore.rb
Instance Method Summary collapse
- #calendar ⇒ Object
- #diary_factory(date, title, body, style = nil) ⇒ Object
-
#initialize(tdiary) ⇒ PStore
constructor
A new instance of PStore.
-
#transaction(date) ⇒ Object
block must be return boolean which dirty diaries.
Constructor Details
#initialize(tdiary) ⇒ PStore
Returns a new instance of PStore.
12 13 14 |
# File 'lib/tdiary/io/pstore.rb', line 12 def initialize( tdiary ) @data_path = tdiary.conf.data_path end |
Instance Method Details
#calendar ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tdiary/io/pstore.rb', line 45 def calendar calendar = {} Dir["#{@data_path}??????"].sort.each do |file| year, month = file.scan( %r[/(\d{4})(\d\d)$] )[0] next unless year calendar[year] = [] unless calendar[year] calendar[year] << month end calendar end |
#diary_factory(date, title, body, style = nil) ⇒ Object
56 57 58 |
# File 'lib/tdiary/io/pstore.rb', line 56 def diary_factory( date, title, body, style = nil ) Diary::new( date, title, body ) end |
#transaction(date) ⇒ Object
block must be return boolean which dirty diaries.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tdiary/io/pstore.rb', line 19 def transaction( date ) diaries = {} filename = date.strftime( "#{@data_path}%Y%m" ) begin PStore::new( filename ).transaction do |db| dirty = false if db.root?( 'diary' ) then diaries.update( db['diary'] ) end dirty = yield( diaries ) if iterator? if dirty != TDiary::TDiaryBase::DIRTY_NONE then db['diary'] = diaries else db.abort end end rescue PStore::Error, NameError, Errno::EACCES raise PermissionError::new( "make your @data_path to writable via httpd. #$!" ) end begin File::delete( filename ) if diaries.empty? rescue Errno::ENOENT end return diaries end |