Class: Noid::Rails::Minter::File

Inherits:
Base
  • Object
show all
Defined in:
lib/noid/rails/minter/file.rb

Overview

A file based minter. This is a simple case.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#mint

Constructor Details

#initialize(template = default_template, statefile = default_statefile) ⇒ File

Returns a new instance of File.



12
13
14
15
# File 'lib/noid/rails/minter/file.rb', line 12

def initialize(template = default_template, statefile = default_statefile)
  @statefile = statefile
  super(template)
end

Instance Attribute Details

#statefileObject (readonly)

Returns the value of attribute statefile.



10
11
12
# File 'lib/noid/rails/minter/file.rb', line 10

def statefile
  @statefile
end

Instance Method Details

#default_statefileObject



17
18
19
# File 'lib/noid/rails/minter/file.rb', line 17

def default_statefile
  Noid::Rails.config.statefile
end

#readObject



21
22
23
24
25
# File 'lib/noid/rails/minter/file.rb', line 21

def read
  with_file do |f|
    state_for(f)
  end
end

#write!(minter) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/noid/rails/minter/file.rb', line 27

def write!(minter)
  with_file do |f|
    # Wipe prior contents so the new state can be written from the beginning of the file
    f.truncate(0)
    f.write(Marshal.dump(minter.dump))
  end
end