Module: Buildrake::Rush

Extended by:
Rush
Included in:
Rush
Defined in:
lib/buildrake/rush.rb

Instance Method Summary collapse

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


114
115
116
# File 'lib/buildrake/rush.rb', line 114

def linux?
  ( "linux" == Rush.os_type )
end

#macos?Boolean

Returns:

  • (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_typeObject



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, options = {}, &block )
  caption = "[#{full_dir_path}] #{command}"
  puts caption
  system( command, options )
  status = $?
  if block_given?
    block.call( status )
  else
    raise "Failed(#{status.exitstatus}): #{caption}" if 0 != status.exitstatus
  end
end

#which?(name) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


118
119
120
# File 'lib/buildrake/rush.rb', line 118

def windows?
  ( "windows" == Rush.os_type )
end