require 'svn/client' class Product < GenericModel attr_reader :id # Dummy id which may be accessed by Rails @@int_id = 1 def initialize(name) super @id = @@int_id @@int_id += 1 end def self.find(what='', params={}) # Cache the products' list @products ||= list_paths(AppConfig.svn['url']).collect {|p| Product.new(p)} if what == :all @products else @products.find { |p| p.name == what } end end def self.count(what='', params={}) find(what, params).size end # Replacements for has_many: def branches self.class.list_paths(AppConfig.svn['url']+'/'+@name+'/branches').collect {|p| Branch.new(p)} end def tags self.class.list_paths(AppConfig.svn['url']+'/'+@name+'/tags').collect {|p| Tag.new(p)} end # Stub class for Errors class MyErrors def count 0 end end # Method which returns the stub Errors class def errors @errors ||= MyErrors.new end # For content_columns class MyColumn attr_accessor :name def initialize(name) @name = name end def human_name @name.capitalize end end def self.content_columns [MyColumn.new('name')] end private # Create SVN context def self.create_context ctx=Svn::Client::Context.new ctx.add_simple_prompt_provider(0) do |cred, realm, may_save, pool| cred.username = AppConfig.svn['user'] cred.password = AppConfig.svn['password'] cred.may_save = false end ctx end # Essentially do a 'list' command def self.list_paths(url) @ctx ||= create_context paths=Array.new @ctx.list(url, 'HEAD') do |path, dirent, lock, abs_path| paths.push(path) end paths.delete("") paths end end