Sha256: 27af1396067e752f842cdac4e21286f00df3555d5d0b0c35ed08f21f480bd447

Contents?: true

Size: 1.26 KB

Versions: 33

Compression:

Stored size: 1.26 KB

Contents

require 'itamae'

module Itamae
  module Resource
    class RemoteFile < File
      SourceNotFoundError = Class.new(StandardError)

      define_attribute :source, type: [String, Symbol], default: :auto

      private

      def content_file
        source_file
      end

      def source_file
        @source_file ||= find_source_file
      end

      def find_source_file
        if attributes.source == :auto
          dirs = attributes.path.split(::File::SEPARATOR)
          dirs.shift if dirs.first == ""

          searched_paths = []
          dirs.size.times do |i|
            source_file_exts.each do |ext|
              path = ::File.join(@recipe.dir, source_file_dir, "#{dirs[i..-1].join("/")}#{ext}")
              if ::File.exist?(path)
                Itamae.logger.debug "#{path} is used as a source file."
                return path
              else
                searched_paths << path
              end
            end
          end

          raise SourceNotFoundError, "source file is not found (searched paths: #{searched_paths.join(', ')})"
        else
          ::File.expand_path(attributes.source, @recipe.dir)
        end
      end

      def source_file_dir
        "files"
      end

      def source_file_exts
        [""]
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
itamae-1.10.3 lib/itamae/resource/remote_file.rb
itamae-1.10.2 lib/itamae/resource/remote_file.rb
itamae-1.10.1 lib/itamae/resource/remote_file.rb
itamae-1.10.0 lib/itamae/resource/remote_file.rb
itamae-1.9.13 lib/itamae/resource/remote_file.rb
itamae-1.9.12 lib/itamae/resource/remote_file.rb
itamae-1.9.11 lib/itamae/resource/remote_file.rb
itamae-1.9.10 lib/itamae/resource/remote_file.rb
itamae-1.9.9 lib/itamae/resource/remote_file.rb
itamae-1.9.8 lib/itamae/resource/remote_file.rb
itamae-1.9.7.pre lib/itamae/resource/remote_file.rb
itamae-1.9.6 lib/itamae/resource/remote_file.rb
itamae-1.9.6.pre lib/itamae/resource/remote_file.rb
itamae-1.9.5 lib/itamae/resource/remote_file.rb
itamae-1.9.4 lib/itamae/resource/remote_file.rb
itamae-mitsurin-0.4 lib/itamae/resource/remote_file.rb
itamae-mitsurin-0.3 lib/itamae/resource/remote_file.rb
itamae-mitsurin-0.2 lib/itamae/resource/remote_file.rb
itamae-mitsurin-0.1 lib/itamae/resource/remote_file.rb
itamae-1.9.3 lib/itamae/resource/remote_file.rb