class Textrepo::Repository

Attributes

name[R]

Repository name. The usage of the value of `name` depends on a concrete repository class. For example, `FileSystemRepository` uses it as a part of the repository path.

type[R]

Repository type. It specifies which concrete repository class will instantiated. For example, the type `:file_system` specifies `FileSystemRepository`.

Public Class Methods

new(conf) click to toggle source

Create a new repository. The argument must be an object which can be accessed like a Hash object.

# File lib/textrepo/repository.rb, line 24
def initialize(conf)
  @type = conf[:repository_type]
  @name = conf[:repository_name]
end

Public Instance Methods

create(Timestamp, Array) → Timestamp click to toggle source

Stores text data into the repository with the specified timestamp. Returns the timestamp.

# File lib/textrepo/repository.rb, line 36
def create(timestamp, text); timestamp; end
delete(Timestamp) → Array click to toggle source

Deletes the content in the repository, which is associated to the timestamp. Returns an array which contains the deleted text.

# File lib/textrepo/repository.rb, line 77
def delete(timestamp); []; end
each() { |pair(timestamp)| ... } click to toggle source

Calls the given block once for each pair of timestamp and text in self, passing those pair as parameter. Returns the repository itself.

If no block is given, an Enumerator is returned.

# File lib/textrepo/repository.rb, line 137
def each(&block)
  if block.nil?
    entries.lazy.map { |timestamp| pair(timestamp) }.to_enum(:each)
  else
    entries.each { |timestamp| yield pair(timestamp) }
    self
  end
end
Also aliased as: each_pair
each_key(&block) click to toggle source

Calls the given block once for each timestamp in self, passing the timestamp as a parameter. Returns the repository itself.

If no block is given, an Enumerator is returned.

# File lib/textrepo/repository.rb, line 154
def each_key(&block)
  if block.nil?
    entries.to_enum(:each)
  else
    entries.each(&block)
  end
end
Also aliased as: each_timestamp
each_pair(&block)
Alias for: each
each_text(&block)
Alias for: each_value
each_timestamp(&block)
Alias for: each_key
each_value() { |read(timestamp)| ... } click to toggle source

Calls the given block once for each timestamp in self, passing the text as a parameter. Returns the repository itself.

If no block is given, an Enumerator is returned.

# File lib/textrepo/repository.rb, line 170
def each_value(&block)
  if block.nil?
    entries.lazy.map { |timestamp| read(timestamp) }.to_enum(:each)
  else
    entries.each { |timestamp| yield read(timestamp) }
  end
end
Also aliased as: each_text
entries(String) → Array of Timestamp instances click to toggle source

Finds all entries of text those have timestamps which mathes the specified pattern of timestamp. Returns an array which contains instances of Timestamp. If none of text was found, an empty array would be returned.

A pattern must be one of the following:

   - yyyymoddhhmiss_lll : whole stamp
   - yyyymoddhhmiss     : omit millisecond part
   - yyyymodd           : date part only
   - yyyymo             : month and year
   - yyyy               : year only
   - modd               : month and day

If `stamp_pattern` is omitted, the recent entries will be listed. Then, how many entries are listed depends on the implementaiton of the concrete repository class.

# File lib/textrepo/repository.rb, line 101
def entries(stamp_pattern = nil); []; end
exist?(Timestamp) → true or false click to toggle source

Check the existence of text which is associated with the given timestamp.

# File lib/textrepo/repository.rb, line 110
def exist?(timestamp); false; end
read(Timestamp) → Array click to toggle source

Reads text data from the repository, which is associated to the timestamp. Returns an array which contains the text.

# File lib/textrepo/repository.rb, line 45
def read(timestamp); []; end
update(Timestamp, Array, true or false) → Timestamp click to toggle source

Updates the content with given text in the repository, which is associated to the given Timestamp object. Returns the Timestamp newly generated during the execution.

When true is passed as the third argument, keeps the Timestamp unchanged, though updates the content. Then, returns the given Timestamp object.

If the given Timestamp object is not existed as a Timestamp attached to text in the repository, raises MissingTimestampError.

If the given text is empty, raises EmptyTextError.

If the given text is identical to the text in the repository, does nothing. Returns the given timestamp itself.

# File lib/textrepo/repository.rb, line 68
def update(timestamp, text, keep_stamp = false); timestamp; end