module GitDS::ModelObject

Instance methods used by a Model object.

Note: This is an instance-method module. It should be included, not extended.

Attributes

db[R]

The database connection for the model. This is expected to be a GitDS::Database object.

name[R]

The name of the model. This is only used for storing configuration variables.

root[R]

The Root item for the Model.

Public Instance Methods

add_fs_item(path, data) click to toggle source

Add an item to the object DB and the filesystem.

# File lib/git-ds/model.rb, line 92
def add_fs_item(path, data)
  # note: @db.add uses exec {} so there is no need to here.
  @db.add(path, data, true)
end
add_item(path, data) click to toggle source

Add an item to the object DB. # Might be better as add child?

# File lib/git-ds/model.rb, line 84
def add_item(path, data)
  # note: @db.add uses exec {} so there is no need to here.
  @db.add(path, data)
end
batch(&block) click to toggle source

Execute a block using an in-memory Staging index.

This isjust a wrapper for Database#batch.

# File lib/git-ds/model.rb, line 141
def batch(&block)
  @db.batch(&block)
end
branched_transaction(name=@db.next_branch_tag(), &block) click to toggle source

Execute a transaction in a branch, then merge if it was successful.

See Database#branch_and_merge.

# File lib/git-ds/model.rb, line 131
def branched_transaction(name=@db.next_branch_tag(), &block)
  raise 'Branched transactions cannot be nested' if @db.staging?
  @db.branch_and_merge(name, &block)
end
config() click to toggle source

Provides access to the Hash of Model-specific config variables.

# File lib/git-ds/model.rb, line 60
def config
  @git_config ||= RepoConfig.new(@db, 'model-' + @name)
end
delete_item(path) click to toggle source

Delete an item from the object DB (and the filesystem, if it exists).

# File lib/git-ds/model.rb, line 107
def delete_item(path)
  # note: @db.delete uses exec {} so there is no need to here.
  @db.delete(path)
end
exec(&block) click to toggle source

Execute block as a database ExecCmd.

# File lib/git-ds/model.rb, line 115
def exec(&block)
  @db.exec(&block)
end
exist?(path)
Alias for: include?
get_item(path) click to toggle source

Return the contents of the BLOB at path.

# File lib/git-ds/model.rb, line 100
def get_item(path)
  @db.object_data(path)
end
include?(path) click to toggle source

Returns true if Model contains path.

# File lib/git-ds/model.rb, line 67
def include?(path)
  @db.include? path
end
Also aliased as: exist?
initialize_model(db, name='generic', root=nil) click to toggle source
# File lib/git-ds/model.rb, line 51
def initialize_model(db, name='generic', root=nil)
  @db = db
  @root = root ? root : RootItem.new(self)
  @name = name
end
list_children(path=root.path) click to toggle source

List children (filenames) of path. Returns [] if path is not a directory.

# File lib/git-ds/model.rb, line 76
def list_children(path=root.path)
  @db.list(path).keys.sort
end
transaction(&block) click to toggle source

Execute block as a database transaction.

# File lib/git-ds/model.rb, line 122
def transaction(&block)
  @db.transaction(&block)
end