Module: Dapp::Dapp::Dappfile

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

Instance Method Summary collapse

Instance Method Details

#configObject



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

def config
  @config ||= begin
    ::Dapp::Config::Config.new(dapp: self).tap do |config|
      begin
        config.instance_eval File.read(dappfile_path), dappfile_path
        config.validate!
      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
  end
end

#dappfile_exists?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/dapp/dapp/dappfile.rb', line 12

def dappfile_exists?
  !!search_file_upward('Dappfile')
end

#dappfile_pathObject

Raises:



16
17
18
19
# File 'lib/dapp/dapp/dappfile.rb', line 16

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

#expand_path(path, number = 1) ⇒ Object



25
26
27
28
29
# File 'lib/dapp/dapp/dappfile.rb', line 25

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

#local_git_artifact_exclude_paths(&blk) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/dapp/dapp/dappfile.rb', line 4

def local_git_artifact_exclude_paths(&blk)
  super do |exclude_paths|
    exclude_paths << 'Dappfile'

    yield exclude_paths if block_given?
  end
end

#work_dirObject



21
22
23
# File 'lib/dapp/dapp/dappfile.rb', line 21

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