class GitDS::ModelItemClassProxy

Proxy a ModelItem class.

This is used to store a link to a ModelItem class instance. A ModelItemList can be passed a ModelItemClassProxy instance as its cls parameter in order to store a list of links to ModelItem class instances.

Public Class Methods

new(cls) click to toggle source
# File lib/git-ds/model/item_proxy.rb, line 28
def initialize(cls)
  @true_class = cls
end

Public Instance Methods

create(parent, args) click to toggle source

Create a link to ModelItem.

The ModelItem class ident() method will be used to find the ident of the instance in the args Hash.

The full path to the instance is expected to be in the :path key of the args Hash.

If args is not nil or false, the link file will be created on-filesystem as well as in-db.

# File lib/git-ds/model/item_proxy.rb, line 74
def create(parent, args)
  link_path = instance_path(parent.path, @true_class.ident(args))
  raise ProxyItemError.new("Invalid ProxyItem path: #{link_path}") if \
        (not link_path) || (link_path.empty?)

  path = args[:path]
  raise ProxyItemError.new('Invalid ModelItem path') if (not path) || \
        (path.empty?)

  # write path to ModelItem into link file at 'instance path'
  args[:fs] ? parent.model.add_fs_item(link_path, path.to_s + "\n") \
            : parent.model.add_item(link_path, path.to_s + "\n")
end
instance_path(base_path, ident) click to toggle source

This is passed to the proxied class, as it just returns class_dir + ident.

# File lib/git-ds/model/item_proxy.rb, line 58
def instance_path(base_path, ident)
  @true_class.instance_path(base_path, ident)
end
list_in_path(model, path) click to toggle source

List ModelItem class instances contained in this list.

Note: this is passed to the proxied class, as it is just a list of idents.

Instantiating and adding an ident is handled by this class.

# File lib/git-ds/model/item_proxy.rb, line 39
def list_in_path(model, path)
  @true_class.list_in_path(model, path)
end
new(model, link_path) click to toggle source

Return instance of ModelItem class for ‘ident’.

# File lib/git-ds/model/item_proxy.rb, line 46
def new(model, link_path)
  # read path to ModelItem instance from link file at 'link_path'
  instance_path = model.get_item(link_path)
  raise ProxyItemError.new("Invalid ProxyItem path: #{link_path}") if \
        (not instance_path) || (instance_path.empty?)

  @true_class.new(model, instance_path.chomp)
end