Class: SvnAuto::Repository
- Inherits:
-
Object
- Object
- SvnAuto::Repository
- Defined in:
- lib/svnauto/repository.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
The name the user gave for this repository.
-
#options ⇒ Object
Additional options to send to svn.
-
#url ⇒ Object
The URL to the repository.
-
#workspace ⇒ Object
get the full path for the workspace.
Class Method Summary collapse
-
.ask(config = nil) ⇒ Object
Prompt the user to enter the necessary attributes for a repository.
- .create_local(path) ⇒ Object
- .default_workspace(name) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Repository
constructor
setup the details for a repository object.
-
#prepare(force) ⇒ Object
make sure the repository is ready to use.
-
#to_s ⇒ Object
convert the repository to a string.
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 (={}) @url = [:url] @name = [:name] @workspace = [:workspace] @options = [:options] end |
Instance Attribute Details
#name ⇒ Object
The name the user gave for this repository
34 35 36 |
# File 'lib/svnauto/repository.rb', line 34 def name @name end |
#options ⇒ Object
Additional options to send to svn
42 43 44 |
# File 'lib/svnauto/repository.rb', line 42 def @options end |
#url ⇒ Object
The URL to the repository
30 31 32 |
# File 'lib/svnauto/repository.rb', line 30 def url @url end |
#workspace ⇒ Object
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) = {} [:name] = Constants::TERMINAL.ask("Repository Name (used with sva -r): ") [: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([: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.(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 [:url] = "file://#{url.path}" end [:workspace] = Constants::TERMINAL.ask("Directory where checkouts go (can be relative to ~/): ") do |q| q.default = default_workspace([:name]) end repository = self.new() 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_s ⇒ Object
convert the repository to a string
126 127 128 |
# File 'lib/svnauto/repository.rb', line 126 def to_s "#{@name} (#{@url})" end |