module GitDS::ModelObject
Instance methods used by a Model
object.
Note: This is an instance-method module. It should be included, not extended.
Attributes
The database connection for the model. This is expected to be a GitDS::Database
object.
The name of the model. This is only used for storing configuration variables.
The Root item for the Model
.
Public Instance Methods
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 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
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
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
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 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
Execute block as a database ExecCmd
.
# File lib/git-ds/model.rb, line 115 def exec(&block) @db.exec(&block) end
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
Returns true if Model
contains path.
# File lib/git-ds/model.rb, line 67 def include?(path) @db.include? path end
# 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 (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
Execute block as a database transaction.
# File lib/git-ds/model.rb, line 122 def transaction(&block) @db.transaction(&block) end