Class: SC::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/sc/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



87
88
89
90
91
92
# File 'lib/sc/repository.rb', line 87

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/sc/repository.rb', line 34

def name
  @name
end

#optionsObject

Additional options to send to svn



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

def options
  @options
end

#urlObject

The URL to the repository



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

def url
  @url
end

#workspaceObject

get the full path for the workspace



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

def workspace
  @workspace
end

Class Method Details

.askObject

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
# File 'lib/sc/repository.rb', line 46

def self.ask
  options = {}

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

  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

  self.new(options)
end

.create_local(path) ⇒ Object



75
76
77
78
# File 'lib/sc/repository.rb', line 75

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



81
82
83
# File 'lib/sc/repository.rb', line 81

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

Instance Method Details

#to_sObject

convert the repository to a string



102
103
104
# File 'lib/sc/repository.rb', line 102

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