Module: DmSvn::Svn::Categorized

Defined in:
lib/dm-svn/svn/categorized.rb

Overview

This module is including when belongs_to is called with :dm-svn => true. It overrides #path and #path= to take into account categories (folders in the Subversion repository). It also overrides .get to accept get_parent argument.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



38
39
40
# File 'lib/dm-svn/svn/categorized.rb', line 38

def included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#pathObject

The path from the svn root for the model. Includes any folders.



44
45
46
47
48
49
50
51
52
# File 'lib/dm-svn/svn/categorized.rb', line 44

def path
  cat = self.send(self.class.svn_category)
  
  if cat && !cat.path.blank?
    return cat.path + "/" + @svn_name
  end
  
  return @svn_name
end

#path=(value) ⇒ Object

Set the path. This is responsible for moving the record to a different parent, etc.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dm-svn/svn/categorized.rb', line 56

def path=(value)
  value = value[1..-1] while value[0..0] == "/"
  ary = value.split("/")
  immediate = ary.pop
  parent = ary.join("/")
  
  if parent.blank?
    self.send("#{self.class.svn_category}=", nil)
  else
    category_model = Object.const_get(self.class.svn_category_model)
    category = category_model.get_or_create(parent)
    self.send("#{self.class.svn_category}=", category)
  end
  
  attribute_set(:svn_name, immediate)
end