Class: Projects
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
Class Method Summary collapse
Instance Method Summary collapse
- #add(args) ⇒ Object
- #clobber(args) ⇒ Object
- #current ⇒ Object
- #filename ⇒ Object
- #get_projects(value = "") ⇒ Object
- #help(args) ⇒ Object
- #import(pattern = "") ⇒ Object
- #info(args) ⇒ Object
-
#initialize(env = nil) ⇒ Projects
constructor
A new instance of Projects.
- #list(args) ⇒ Object
- #make(args) ⇒ Object
- #open ⇒ Object
- #pull ⇒ Object
- #rake ⇒ Object
- #remove(args) ⇒ Object
- #save ⇒ Object
- #update(args) ⇒ Object
- #work(args) ⇒ Object
Methods inherited from Hash
Constructor Details
#initialize(env = nil) ⇒ Projects
Returns a new instance of Projects.
16 17 18 19 20 |
# File 'lib/base/projects.rb', line 16 def initialize(env = nil) @env = env if env.is_a?(Environment) @env = Environment.new if @env.nil? open end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
14 15 16 |
# File 'lib/base/projects.rb', line 14 def env @env end |
Class Method Details
.current ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/base/projects.rb', line 195 def self.current project = nil url = Git.remote_origin url = Svn.url if url.length.zero? if Rake.application.original_dir.include?("/wrk/") && url.length.positive? project = Project.new(url) fullname = Rake.application.original_dir.gsub("#{Environment.dev_root}/wrk/", "") project[:fullname] = name if name.length.positive? && !name.include?(Environment.dev_root) if defined?(PROJECTS) PROJECTS[name] = project unless PROJECTS.key?(name) project.each { |k, v| PROJECTS[name][k] = v } PROJECTS.save else project[:fullname] = name end end project end |
.user_projects_filename ⇒ Object
190 191 192 193 |
# File 'lib/base/projects.rb', line 190 def self.user_projects_filename FileUtils.mkdir_p("#{Environment.dev_root}/data") unless File.exist?("#{Environment.dev_root}/data") "#{Environment.dev_root}/data/PROJECTS.json" end |
Instance Method Details
#add(args) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/base/projects.rb', line 79 def add(args) url = args[0] project = Project.new(url) project[:fullname] = args[1] if args.length > 1 project.set_timeout args[2] if args.length > 2 if !key?(project[:fullname]) && project[:fullname].length.positive? @env.out "adding #{project.fullname}\n" self[project.fullname] = project save end end |
#clobber(args) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/base/projects.rb', line 161 def clobber(args) projects = get_projects args puts "clobbering #{projects.length} projects..." if @env.debug? projects.each do |project| project.clobber # Dir.remove_empty @env.wrk_dir rescue StandardError => e puts "error raised during clobber #{project.fullname}" puts "--------------------------------------------" puts e puts "--------------------------------------------" end end |
#current ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/base/projects.rb', line 26 def current fullname = Rake.application.original_dir.gsub("#{Environment.default.wrk_dir}/", "") if key? fullname self[fullname] else project = nil begin project = Project.new(Project.get_url, fullname) rescue StandardError project = nil end project end end |
#filename ⇒ Object
22 23 24 |
# File 'lib/base/projects.rb', line 22 def filename "#{@env.root_dir}/data/Projects.json" end |
#get_projects(value = "") ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/base/projects.rb', line 59 def get_projects(value = "") puts "get_projects #{value}" if @env.debug? puts "get_project total project count #{length}" if @env.debug? projects = [] filter = "" filter = value.to_s if !value.nil? && value.is_a?(String) filter = value[0].to_s if !value.nil? && value.is_a?(Array) && !value[0].to_s.include?("=") puts "get_project filter '#{filter}'" if @env.debug? each do |k, v| puts " checking project #{k}" if @env.debug? puts " v.class #{v.class}" if @env.debug? if (filter.length.zero? || k.include?(filter)) && v.is_a?(Project) projects << v v.env = @env end end projects end |
#help(args) ⇒ Object
104 |
# File 'lib/base/projects.rb', line 104 def help(args); end |
#import(pattern = "") ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/base/projects.rb', line 223 def import(pattern = "") wrk = @env.wrk_dir if File.exist?(wrk) Dir.chdir(wrk) do puts "scanning #{wrk} for imports..." Dir.glob("**/rakefile.rb").each do |rakefile| rakedir = File.dirname(rakefile) url = Project.get_url rakedir project = Project.new(Project.get_url(rakedir)) project[:fullname] = rakedir.gsub(@env.wrk_dir, "") if project.fullname.include?(":") if (pattern.length.zero? || project.fullname.include?(pattern)) && (project.fullname.length.positive? && !key?(project.fullname)) puts "importing #{project.fullname}" self[project.fullname] = project end end end save end end |
#info(args) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/base/projects.rb', line 122 def info(args) projects = get_projects args puts "collecting info for #{projects.length} projects..." if @env.debug? exit_code = 0 projects.each do |project| result = project.info exit_code = result.exit_code if result.exit_code != 0 rescue StandardError => e puts "error raised during work #{project.fullname}" puts "--------------------------------------------" puts e puts "--------------------------------------------" end exit_code end |
#list(args) ⇒ Object
138 139 140 141 142 143 |
# File 'lib/base/projects.rb', line 138 def list(args) projects = get_projects args puts "listing #{projects.length} projects..." if @env.debug? projects.each(&:list) 0 end |
#make(args) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/base/projects.rb', line 145 def make(args) projects = get_projects args puts "making #{projects.length} projects..." if @env.debug? exit_code = 0 projects.each do |project| result = project.make exit_code = result.exit_code if result.exit_code != 0 rescue StandardError => e puts "error raised during make #{project.fullname}" puts "--------------------------------------------" puts e puts "--------------------------------------------" end exit_code end |
#open ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/base/projects.rb', line 46 def open if File.exist? filename JSON.parse(IO.read(filename)).each do |k, v| self[k] = if v.is_a?(Project) v else Project.new(v) end end # update_state end end |
#pull ⇒ Object
215 216 217 |
# File 'lib/base/projects.rb', line 215 def pull each { |_k, v| v.pull if v.respond_to?("pull".to_sym) } end |
#rake ⇒ Object
219 220 221 |
# File 'lib/base/projects.rb', line 219 def rake each { |_k, v| v.rake if v.respond_to?("rake".to_sym) } end |
#remove(args) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/base/projects.rb', line 91 def remove(args) projects = get_projects args puts "removing #{projects.length} projects..." if @env.debug? remove_keys = [] projects.each do |project| project.clobber remove_keys << project.fullname end remove_keys.each { |key| delete(key) } save 0 end |
#save ⇒ Object
41 42 43 44 |
# File 'lib/base/projects.rb', line 41 def save Dir.make File.dirname(filename) unless File.exist? File.dirname(filename) File.open(filename, "w") { |f| f.write(JSON.pretty_generate(self)) } end |
#update(args) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/base/projects.rb', line 175 def update(args) projects = get_projects args puts "updating #{projects.length} projects..." if @env.debug? projects.each do |project| puts "updating #{project.fullname}" if @env.debug? result = project.update exit_code = result.exit_code if result.exit_code != 0 rescue StandardError => e puts "error raised during update #{project.fullname}" puts "--------------------------------------------" puts e puts "--------------------------------------------" end end |
#work(args) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/base/projects.rb', line 106 def work(args) projects = get_projects args puts "working #{projects.length} projects..." if @env.debug? exit_code = 0 projects.each do |project| result = project.work exit_code = result.exit_code if result.exit_code != 0 rescue StandardError => e puts "error raised during work #{project.fullname}" puts "--------------------------------------------" puts e puts "--------------------------------------------" end exit_code end |