Module: Dapp::Project::Dappfile

Included in:
Dapp::Project
Defined in:
lib/dapp/project/dappfile.rb

Overview

Dappfile

Instance Method Summary collapse

Instance Method Details

#build_configsObject



6
7
8
9
10
11
12
# File 'lib/dapp/project/dappfile.rb', line 6

def build_configs
  @configs ||= begin
    dimgs(dappfile_path).flatten.tap do |dimgs|
      raise Error::Project, code: :no_such_dimg, data: { dimgs_patterns: dimgs_patterns.join(', ') } if dimgs.empty?
    end
  end
end

#dappfile_pathObject

Raises:



14
15
16
17
# File 'lib/dapp/project/dappfile.rb', line 14

def dappfile_path
  raise Error::Project, code: :dappfile_not_found unless (dappfile_path = search_file_upward('Dappfile'))
  dappfile_path
end

#dimgs(dappfile_path) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dapp/project/dappfile.rb', line 29

def dimgs(dappfile_path)
  Config::DimgGroupMain.new(project: self) do |conf|
    begin
      conf.instance_eval File.read(dappfile_path), dappfile_path
    rescue SyntaxError, StandardError => e
      backtrace = e.backtrace.find { |line| line.start_with?(dappfile_path) }
      message = begin
        case e
        when NoMethodError
          e.message =~ /`.*'/
          "undefined method #{Regexp.last_match}"
        when NameError then e.message[/.*(?= for)/]
        else
          e.message
        end
      end
      message = "#{backtrace[/.*(?=:in)/]}: #{message}" if backtrace
      raise Error::Dappfile, code: :incorrect, data: { error: e.class.name, message: message }
    end
  end._dimg.select { |dimg| dimgs_patterns.any? { |pattern| dimg._name.nil? || File.fnmatch(pattern, dimg._name) } }.tap do |dimgs|
    dimgs.each { |dimg| dimg.send(:validate!) }
  end
end

#expand_path(path, number = 1) ⇒ Object



23
24
25
26
27
# File 'lib/dapp/project/dappfile.rb', line 23

def expand_path(path, number = 1)
  path = File.expand_path(path)
  number.times.each { path = File.dirname(path) }
  path
end

#work_dirObject



19
20
21
# File 'lib/dapp/project/dappfile.rb', line 19

def work_dir
  File.expand_path(cli_options[:dir] || Dir.pwd)
end