Class: SvnAuto::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/svnauto/repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Repository

setup the details for a repository object



95
96
97
98
99
100
# File 'lib/svnauto/repository.rb', line 95

def initialize (options={})
  @url        = options[:url]
  @name       = options[:name]
  @workspace  = options[:workspace]
  @options    = options[:options]
end

Instance Attribute Details

#nameObject

The name the user gave for this repository



34
35
36
# File 'lib/svnauto/repository.rb', line 34

def name
  @name
end

#optionsObject

Additional options to send to svn



42
43
44
# File 'lib/svnauto/repository.rb', line 42

def options
  @options
end

#urlObject

The URL to the repository



30
31
32
# File 'lib/svnauto/repository.rb', line 30

def url
  @url
end

#workspaceObject

get the full path for the workspace



38
39
40
# File 'lib/svnauto/repository.rb', line 38

def workspace
  @workspace
end

Class Method Details

.ask(config = nil) ⇒ Object

Prompt the user to enter the necessary attributes for a repository



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/svnauto/repository.rb', line 46

def self.ask (config=nil)
  options = {}

  options[:name] = Constants::TERMINAL.ask("Repository Name (used with sva -r): ")

  options[:url]  = Constants::TERMINAL.ask("Repository URL: ") do |question|
    if config
      project = Project.from_cwd(config)
      question.default = project.repository.url unless project.repository.nil?
    end
  end

  url = URI.parse(options[:url])
  if url.scheme.nil? and Constants::TERMINAL.agree("Repository URL is missing protocol, assume it's local? ")
    url.scheme = 'file'
  end

  if url.scheme.downcase == 'file'
    url.path = File.expand_path(url.path)

    if !File.exist?(url.path) and Constants::TERMINAL.agree("Local repository does not exist, should I create it? ")
      create_local(url.path)
    end

    options[:url] = "file://#{url.path}"
  end

  options[:workspace] = Constants::TERMINAL.ask("Directory where checkouts go (can be relative to ~/): ") do |q|
    q.default = default_workspace(options[:name])
  end

  repository = self.new(options)
  repository.prepare(false)
  repository
end

.create_local(path) ⇒ Object



83
84
85
86
# File 'lib/svnauto/repository.rb', line 83

def self.create_local (path)
  Dir.mkdir(path) unless File.exist?(path)
  system('svnadmin', 'create', path, '--fs-type', 'fsfs') or exit 1
end

.default_workspace(name) ⇒ Object



89
90
91
# File 'lib/svnauto/repository.rb', line 89

def self.default_workspace (name)
  "develop/#{name.gsub(/[^\w_-]+/, '_').downcase}"
end

Instance Method Details

#prepare(force) ⇒ Object

make sure the repository is ready to use



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/svnauto/repository.rb', line 104

def prepare (force)
  workspace_dir = workspace()
  
  unless File.exist?(workspace_dir)
    question = "Create workspace "
    question << Constants::TERMINAL.color(workspace_dir, :green)
    question << "? "

    if force or Constants::TERMINAL.agree(question)
      Pathname.new(workspace_dir).mkpath
    end
  end
end

#to_sObject

convert the repository to a string



126
127
128
# File 'lib/svnauto/repository.rb', line 126

def to_s 
  "#{@name} (#{@url})"
end