Class: DevTasks
- Inherits:
-
Hash
- Object
- Hash
- DevTasks
- Defined in:
- lib/dev_tasks.rb
Instance Attribute Summary collapse
-
#timer ⇒ Object
Returns the value of attribute timer.
Instance Method Summary collapse
- #add(hash) ⇒ Object
- #define_task(task_name) ⇒ Object
- #execute(cmd) ⇒ Object
- #execute_task(task) ⇒ Object
-
#initialize ⇒ DevTasks
constructor
A new instance of DevTasks.
- #setup_copy(src, dest) ⇒ Object
- #setup_svn_export(uri, dir) ⇒ Object
- #update ⇒ Object
- #update_tasks ⇒ Object
Constructor Details
#initialize ⇒ DevTasks
Returns a new instance of DevTasks.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dev_tasks.rb', line 23 def initialize @timer = Timer.new self[:name]=pwd.split('/').last#Rake.application.original_dir.split('/').last self[:svn_exports]=SvnExports.new self[:scm]=Environment.scm self[:scm_origin]=Environment.scm_origin self[:branch]=Environment.branch self[:src_glob]="**/{*.{rb,feature,spec,cs,c,m,cpp,cxx,h,hpp,i,jam,csproj,vcproj,snk,vcxproj,xcodeproj,plist,xib,sln,filters,xaml,resx,settings,config},Jamfile,.semver,Gemfile,README,LICENSE}" self[:newest_src_file]=Dir.glob(self[:src_glob]).max_by {|f| File.mtime(f)} self[:command_order]=['pull','upgrade','setup','add','build','test','commit','push','verify','publish'] self[:relative_directory]=Environment.relative_directory self[:working_directory]=Environment.working_directory self[:context]=Environment.context self[:machine]=Environment.machine self[:platform]=RUBY_PLATFORM self[:dev_root]=Environment.dev_root self[:settings]=Settings.new self[:commands]=Commands.new update end |
Instance Attribute Details
#timer ⇒ Object
Returns the value of attribute timer.
21 22 23 |
# File 'lib/dev_tasks.rb', line 21 def timer @timer end |
Instance Method Details
#add(hash) ⇒ Object
45 46 47 48 49 |
# File 'lib/dev_tasks.rb', line 45 def add hash hash.each do |key,value| self[key]=value if !has_key?(key) end end |
#define_task(task_name) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/dev_tasks.rb', line 94 def define_task task_name if(!Rake::Task.task_defined?(task_name)) ruby="desc '#{task_name} task';task :#{task_name} do;DEV_TASKS.execute_task '#{task_name}';end" eval(ruby) end end |
#execute(cmd) ⇒ Object
74 75 76 |
# File 'lib/dev_tasks.rb', line 74 def execute cmd self[:commands].execute_command cmd end |
#execute_task(task) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/dev_tasks.rb', line 78 def execute_task task sym_task = task.to_sym timer=Timer.new Console.announce_task_start task if(!self[:commands].has_key?(sym_task)) puts "no commands discovered for task " + task else self[:commands][sym_task].each {|c| self[:commands].execute_command(c) } end elapsed = timer.elapsed if elapsed > 30 elapsed_str="[" + "%.0f" %(elapsed) + "s]" Console.announce_task_end task, elapsed_str end end |
#setup_copy(src, dest) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/dev_tasks.rb', line 116 def setup_copy(src,dest) if(File.exists?(src)) FileUtils.mkdir_p(File.dirname(dest)) if(!File.exists?(File.dirname(dest))) if(!File.exists?(dest)) DEV_TASKS[:commands][:setup] << "<%FileUtils.cp('#{src}','#{dest}')%>" end else if(src.kind_of?(Array)) src.each{|s|setup_copy(s,dest)} end end end |
#setup_svn_export(uri, dir) ⇒ Object
112 113 114 |
# File 'lib/dev_tasks.rb', line 112 def setup_svn_export(uri,dir) DEV_TASKS[:commands][:setup] << "svn export #{uri} #{dir}" if(!File.exists?(dir)) end |
#update ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dev_tasks.rb', line 51 def update self[:dependencies]=Dependencies.new if !has_key?(:dependencies) self[:artifacts]=Artifacts.new if !has_key?(:artifacts) self[:artifacts].update allartifactsexist = true self[:artifacts].each{|f| allartifactsexist=false if !File.exists?(f)} self[:newest_artifact]=self[:artifacts].max_by { |f| File.mtime(f) } if allartifactsexist self[:commands]=Commands.new if !has_key?(:commands) self[:commands].update self[:up_to_date] = false if(allartifactsexist && !self[:newest_artifact].nil? && !self[:newest_src_file].nil? && File.exists?(self[:newest_artifact]) && File.exists?(self[:newest_src_file])) if(File.mtime(self[:newest_artifact]) > File.mtime(self[:newest_src_file])) self[:command_order]=['upgrade'] if(File.mtime(self[:newest_artifact]) > File.mtime(self[:newest_src_file])) self[:up_to_date]=true end self[:newest_artifact_mtime]=File.mtime(self[:newest_artifact]).to_s self[:newest_src_file_mtime]=File.mtime(self[:newest_src_file]).to_s end update_tasks end |
#update_tasks ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/dev_tasks.rb', line 101 def update_tasks dev_task_defaults=Array.new self[:commands].each do |key,array| if(array.length > 0) define_task key dev_task_defaults << key end end end |