class DtkCommon::GitRepo

Constants

AdapterConditions
AdaptersForMethods

for each hash value form is scalar or array of adapters to try in order

Public Class Methods

implements_method?(method_name) click to toggle source
# File lib/git_repo.rb, line 58
def self.implements_method?(method_name)
  !!find_adapter_name(method_name)
end
new(repo_path) click to toggle source
# File lib/git_repo.rb, line 26
def initialize(repo_path)
  @repo_path = repo_path
  @adapters = Hash.new
end

Private Class Methods

find_adapter_name(method_name) click to toggle source
# File lib/git_repo.rb, line 85
def self.find_adapter_name(method_name)
  @adapter_names ||= Hash.new
  return @adapter_names[method_name] if @adapter_names.has_key?(method_name)
  ret = Array(AdaptersForMethods[method_name]||[]).find do |adapter_name|
    condition = AdapterConditions[adapter_name]
    condition.nil? or condition.call()
  end
  @adapter_names[method_name] = ret 
end
load_and_return_adapter_class(adapter_name) click to toggle source
# File lib/git_repo.rb, line 81
def self.load_and_return_adapter_class(adapter_name)
  (@adapter_classes ||= Hash.new)[adapter_name] ||= DynmamicLoader.load_and_return_adapter_class(:git_repo,adapter_name,:base_class => Adapter)
end

Public Instance Methods

method_missing(method_name,*args,&block) click to toggle source
Calls superclass method
# File lib/git_repo.rb, line 42
def method_missing(method_name,*args,&block)
  if adapter_name = self.class.find_adapter_name(method_name)
    
    adapter = (@adapters[adapter_name] ||= Hash.new)[branch_index()] ||= self.class.load_and_return_adapter_class(adapter_name).new(*adapter_initialize_args())
    execution_wrapper do
      adapter.send(method_name,*args,&block)
    end
  else
    super
  end
end
respond_to?(method_name) click to toggle source
Calls superclass method
# File lib/git_repo.rb, line 54
def respond_to?(method_name)
  super(method_name) or self.class.find_adapter_name(method_name)
end

Private Instance Methods

adapter_initialize_args() click to toggle source
# File lib/git_repo.rb, line 63
def adapter_initialize_args()
  [@repo_path]
end
branch_index() click to toggle source
# File lib/git_repo.rb, line 67
def branch_index()
  @branch||"---NONE"
end
execution_wrapper() { || ... } click to toggle source
# File lib/git_repo.rb, line 71
def execution_wrapper(&block)
  begin
    yield
   rescue => e 
    Log.error(([e.to_s]+e.backtrace).join("\n"))
    error = (e.kind_of?(::DtkCommon::Error) ? e : ::DtkCommon::Error.new(e.to_s))
    raise error
  end
end