Sha256: 323720fd3b883c6818d1c77ff6c607434c8df0ab22c6cd018b0da8abf72dcf98

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'arli'
require 'yaml'
require 'forwardable'
require 'arduino/library'

module Arli
  class ArliFile
    require 'arduino/library/include'

    include Enumerable

    extend Forwardable
    def_delegators :@dependencies, *(Array.new.methods - Object.methods)

    attr_accessor :dependencies, :file_hash, :file, :lib_path, :resolved

    def initialize(lib_path: Arli.library_path,
                   arlifile_path: nil)

      self.lib_path = lib_path
      self.file     = arlifile_path ? "#{arlifile_path}/#{Arli::Config::DEFAULT_FILENAME}" :
                        Arli::Config::DEFAULT_FILENAME
      raise(Arli::Errors::ArliFileNotFound, 'Arlifile could not be found') unless file || !File.exist?(file)
      self.dependencies = []

      parse!
    end


    def libraries
      self.dependencies
    end

    def within_lib_path
      FileUtils.mkpath(lib_path) unless Dir.exist?(lib_path)
      Dir.chdir(lib_path) do
        yield if block_given?
      end
    end

    def each_dependency(&_block)
      within_lib_path do
        dependencies.each do |dependency|
          yield(dependency)
        end
      end
    end

    def error(*args)
      STDERR.puts *args.join("\n")
    end

    def info(*args)
      STDOUT.puts *args.join("\n") if Arli.debug?
    end

    private

    def parse!
      self.file_hash    = ::YAML.load(::File.read(self.file))
      self.dependencies = file_hash['dependencies'].map do |lib|
        ::Arduino::Library::Model.from_hash(lib)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arli-0.5.1 lib/arli/arli_file.rb