Sha256: 71f20c9ed0f51aef18c6757b58040c9577fe40b8948c8543a952c17bf7d206b7

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

require 'awesome_print'
require 'arli/errors'

require_relative 'installer'
require_relative 'multi_version'

module Arli
  module Library
    # Represents a wrapper around Arduino::Library::Model instance
    # and decorates with a few additional helpers.
    class SingleVersion
      attr_accessor :lib,
                    :lib_dir,
                    :canonical_dir,
                    :config

      # Additional attributes that can be set via Arlifile
      attr_accessor :headers_only,
                    :depends,
                    :folder # indicates a sub-folder of the library

      def initialize(lib, config: Arli.config)
        self.lib          = lib
        self.config       = config
        self.lib_dir      = lib.name.gsub(/ /, '_')
        self.headers_only = false
        self.depends      = nil
        self.folder       = nil
      end

      def install
        installer.install
      end

      def installer
        @installer ||= Installer.new(self)
      end

      def libraries_home
        config.libraries.path
      end

      def temp_dir
        config.libraries.temp_dir
      end

      def dir
        canonical_dir || lib_dir
      end

      def path
        libraries_home + '/' + dir
      end

      def temp_path
        temp_dir + '/' + dir
      end

      def exists?
        Dir.exist?(path)
      end

      def inspect
        <<-EOF
Library: #{lib.name} (#{lib.url}), only headers? #{headers_only ? 'YES' : 'NO'}
        EOF
      end

      def method_missing(method, *args, &block)
        if lib && lib.respond_to?(method)
          lib.send(method, *args, &block)
        else
          super(method, *args, &block)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
arli-1.4.0 lib/arli/library/single_version.rb
arli-1.3.0 lib/arli/library/single_version.rb