Module: Buildrake::Rush
Instance Method Summary collapse
- #base_name(path) ⇒ Object
- #changed(path, &block) ⇒ Object
- #copy(src, dst) ⇒ Object
- #dir?(path) ⇒ Boolean
- #dir_path(path) ⇒ Object
- #env(key, value = nil) ⇒ Object
- #env?(key) ⇒ Boolean
- #ext_name(path) ⇒ Object
- #file?(path) ⇒ Boolean
- #find(pattern, &block) ⇒ Object
- #full_dir_path(path = ".") ⇒ Object
- #linux? ⇒ Boolean
- #macos? ⇒ Boolean
- #maked(path, &block) ⇒ Object
- #os_type ⇒ Object
- #pascal_case(name) ⇒ Object
- #remaked(path, &block) ⇒ Object
- #remove(path) ⇒ Object
- #rename(src, dst) ⇒ Object
- #sh(command, options = {}, &block) ⇒ Object
- #which?(name) ⇒ Boolean
- #windows? ⇒ Boolean
Instance Method Details
#base_name(path) ⇒ Object
61 62 63 |
# File 'lib/buildrake/rush.rb', line 61 def base_name( path ) File.basename( path ) end |
#changed(path, &block) ⇒ Object
31 32 33 |
# File 'lib/buildrake/rush.rb', line 31 def changed( path, &block ) Dir.chdir( path, &block ) end |
#copy(src, dst) ⇒ Object
45 46 47 |
# File 'lib/buildrake/rush.rb', line 45 def copy( src, dst ) FileUtils.cp_r( src, dst ) end |
#dir?(path) ⇒ Boolean
27 28 29 |
# File 'lib/buildrake/rush.rb', line 27 def dir?( path ) Dir.exists?( path ) end |
#dir_path(path) ⇒ Object
69 70 71 |
# File 'lib/buildrake/rush.rb', line 69 def dir_path( path ) File.dirname( path ) end |
#env(key, value = nil) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/buildrake/rush.rb', line 84 def env( key, value = nil ) if value.nil? && Rush.env?( key ) value = ENV[ key ] else ENV[ key ] = value end value end |
#env?(key) ⇒ Boolean
80 81 82 |
# File 'lib/buildrake/rush.rb', line 80 def env?( key ) ENV.key?( key ) end |
#ext_name(path) ⇒ Object
65 66 67 |
# File 'lib/buildrake/rush.rb', line 65 def ext_name( path ) File.extname( path ).gsub( /^\./, "" ) end |
#file?(path) ⇒ Boolean
23 24 25 |
# File 'lib/buildrake/rush.rb', line 23 def file?( path ) File.exists?( path ) end |
#find(pattern, &block) ⇒ Object
57 58 59 |
# File 'lib/buildrake/rush.rb', line 57 def find( pattern, &block ) Dir.glob( pattern, &block ) end |
#full_dir_path(path = ".") ⇒ Object
73 74 75 76 77 78 |
# File 'lib/buildrake/rush.rb', line 73 def full_dir_path( path = "." ) Rush.changed( path ){ path = Dir.pwd } path end |
#linux? ⇒ Boolean
114 115 116 |
# File 'lib/buildrake/rush.rb', line 114 def linux? ( "linux" == Rush.os_type ) end |
#macos? ⇒ Boolean
110 111 112 |
# File 'lib/buildrake/rush.rb', line 110 def macos? ( "macos" == Rush.os_type ) end |
#maked(path, &block) ⇒ Object
35 36 37 38 |
# File 'lib/buildrake/rush.rb', line 35 def maked( path, &block ) FileUtils.mkdir_p( path ) if ! Rush.dir?( path ) Rush.changed( path, &block ) end |
#os_type ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/buildrake/rush.rb', line 97 def os_type os_type = RbConfig::CONFIG[ "host_os" ] case os_type when /darwin/ os_type = "macos" when /linux/ os_type = "linux" when /mingw/ os_type = "windows" end os_type end |
#pascal_case(name) ⇒ Object
93 94 95 |
# File 'lib/buildrake/rush.rb', line 93 def pascal_case( name ) name.split( "_" ).map{|v| v.capitalize}.join end |
#remaked(path, &block) ⇒ Object
40 41 42 43 |
# File 'lib/buildrake/rush.rb', line 40 def remaked( path, &block ) Rush.remove( path ) Rush.maked( path, &block ) end |
#remove(path) ⇒ Object
53 54 55 |
# File 'lib/buildrake/rush.rb', line 53 def remove( path ) FileUtils.rm_rf( path ) if Rush.file?( path ) || Rush.dir?( path ) end |
#rename(src, dst) ⇒ Object
49 50 51 |
# File 'lib/buildrake/rush.rb', line 49 def rename( src, dst ) FileUtils.mv( src, dst ) end |
#sh(command, options = {}, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/buildrake/rush.rb', line 7 def sh( command, = {}, &block ) caption = "[#{full_dir_path}] #{command}" puts caption system( command, ) status = $? if block_given? block.call( status ) else raise "Failed(#{status.exitstatus}): #{caption}" if 0 != status.exitstatus end end |
#which?(name) ⇒ Boolean
19 20 21 |
# File 'lib/buildrake/rush.rb', line 19 def which?( name ) Rush.sh( "which #{name}", :out => "/dev/null", :err => "/dev/null" ){|status| return ( 0 == status )} end |
#windows? ⇒ Boolean
118 119 120 |
# File 'lib/buildrake/rush.rb', line 118 def windows? ( "windows" == Rush.os_type ) end |