Module: Dapp::Helper::Trivia

Included in:
CLI, Dapp, Dapp, Dimg::Build::Stage::Base, Dimg::Dimg
Defined in:
lib/dapp/helper/trivia.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.class_to_lowercase(class_name = self) ⇒ Object



31
32
33
# File 'lib/dapp/helper/trivia.rb', line 31

def self.class_to_lowercase(class_name = self)
  class_name.to_s.split('::').last.split(/(?=[[:upper:]]|[0-9])/).join('_').downcase.to_s
end

Instance Method Details

#class_to_lowercase(class_name = self.class) ⇒ Object



8
9
10
# File 'lib/dapp/helper/trivia.rb', line 8

def class_to_lowercase(class_name = self.class)
  Trivia.class_to_lowercase(class_name)
end

#delete_file(path) ⇒ Object



12
13
14
15
# File 'lib/dapp/helper/trivia.rb', line 12

def delete_file(path)
  path = Pathname(path)
  path.delete if path.exist?
end

#kwargs(args) ⇒ Object



4
5
6
# File 'lib/dapp/helper/trivia.rb', line 4

def kwargs(args)
  args.last.is_a?(Hash) ? args.pop : {}
end

#make_path(base, *path) ⇒ Object



27
28
29
# File 'lib/dapp/helper/trivia.rb', line 27

def make_path(base, *path)
  Pathname.new(File.join(base.to_s, *path.compact.map(&:to_s)))
end

#search_file_upward(filename) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/dapp/helper/trivia.rb', line 17

def search_file_upward(filename)
  cdir = Pathname(work_dir)
  loop do
    if (path = cdir.join(filename)).exist?
      return path.to_s
    end
    break if (cdir = cdir.parent).root?
  end
end