Class: Monk
- Inherits:
-
Thor
- Object
- Thor
- Monk
- Includes:
- Thor::Actions
- Defined in:
- lib/monk.rb,
lib/monk/skeleton.rb
Defined Under Namespace
Classes: Skeleton
Class Method Summary collapse
- .git_option(name, options = {}) ⇒ Object
- .git_options ⇒ Object
- .monk_home ⇒ Object
- .monk_mirrors ⇒ Object
Instance Method Summary collapse
- #add(name, repository_url) ⇒ Object
- #change(name) ⇒ Object
- #cleanup ⇒ Object
- #copy(from, to) ⇒ Object
- #init(target = ".") ⇒ Object
- #list ⇒ Object
- #rm(name) ⇒ Object
- #show(name) ⇒ Object
- #update(name = nil) ⇒ Object
Class Method Details
.git_option(name, options = {}) ⇒ Object
13 14 15 16 |
# File 'lib/monk.rb', line 13 def self.git_option(name, = {}) class_option name, .merge(:group => :git) << name.to_s end |
.git_options ⇒ Object
18 19 20 |
# File 'lib/monk.rb', line 18 def self. @git_options ||= ["mirror_path"] end |
.monk_home ⇒ Object
22 23 24 |
# File 'lib/monk.rb', line 22 def self.monk_home ENV["MONK_HOME"] || File.join(Thor::Util.user_home) end |
.monk_mirrors ⇒ Object
26 27 28 |
# File 'lib/monk.rb', line 26 def self.monk_mirrors File.join(monk_home, ".monk_mirrors") end |
Instance Method Details
#add(name, repository_url) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/monk.rb', line 59 def add(name, repository_url) monk_config[name] = Skeleton.new(repository_url) monk_config[name].merge! monk_config[name].update_mirror write_monk_config_file say_status :added, name end |
#change(name) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/monk.rb', line 68 def change(name) if monk_config.include? name monk_config[name].merge! if .include? "mirror" and not .mirror? path = monk_config[name].delete "mirror_path" system "rm -R #{path}" if path end write_monk_config_file say_status :modified, name else say_status name, "repository not found" end end |
#cleanup ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/monk.rb', line 101 def cleanup say_status "scanning", "mirrors" mirrors = Dir.glob File.join(Monk.monk_mirrors, "*") monk_config.each_value do |skel| mirrors.delete skel.mirror_path if skel.mirror_path? end unless ["all"] say_status "cleanup", "mirrors" system "rm -R #{mirrors.join " "}" end |
#copy(from, to) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/monk.rb', line 91 def copy(from, to) return unless monk_config.include? from monk_config[to] = skeleton(from) monk_config[to].delete "mirror_path" write_monk_config_file say_status :added, to end |
#init(target = ".") ⇒ Object
41 42 43 44 45 46 |
# File 'lib/monk.rb', line 41 def init(target = ".") say_status :fetching, skeleton.url skeleton.create(target) ? say_status(:initialized, target) : say_status(:error, clone_error(target)) end |
#list ⇒ Object
54 55 56 |
# File 'lib/monk.rb', line 54 def list monk_config.keys.sort.each { |key| show(key) } end |
#rm(name) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/monk.rb', line 83 def rm(name) skel = monk_config.delete(name) write_monk_config_file system "rm -R #{skel.mirror_path}" if skel.mirror_path? say_status :deleted, name end |
#show(name) ⇒ Object
49 50 51 |
# File 'lib/monk.rb', line 49 def show(name) say_status name, monk_config[name] ? skeleton(name).description : "repository not found" end |
#update(name = nil) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/monk.rb', line 112 def update(name = nil) name ||= [:skeleton] return monk_config.each_key { |s| update(s) } unless name skel = skeleton(name) if skel.mirror? say_status "update", name skel.update_mirror end end |