Sha256: e16a266b08ee1471a54ab6fbbecef734881e68e568274d062473d5d555112ec9

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'thor/error'

module Lanes
    module Command
        class << self

            # Reads and returns the contents of a usage file.  Used
            # internally by commands to populate their long_desc
            # @param [String] basename of file to read usage from
            def usage_from_file(file)
                Pathname.new(__FILE__).dirname.join("command","#{file}.usage").read
            end

            # Loads the code for the extension that the user is currently
            # working inside.  The `lanes` command uses this to detect
            # what actions should be taken.
            #
            # Will silently swallow any exceptions that are raised when the file is required and return nil
            #
            # @return [Extension] extension that was loaded, nil if none was found
            def load_current_extension(raise_on_fail:false)
                
                previous = Extensions.all
                ext = Dir.glob("./lib/*/extension.rb").first
                if ext
                    begin
                        require(ext)
                    rescue =>e
                        stack = e.backtrace[0..4].join("\n")
                        raise Thor::Error.new("Loading ./lib/*/extension.rb failed with: #{e}\n#{stack}")
                    end
                    all = Extensions.all
                    if all.any?
                        diff = all - previous
                        return diff.any? ? diff.first.new : Extensions.all.first.new
                    end
                else
                    return _maybe_fail(raise_on_fail)
                end
            end

            def _maybe_fail(should_raise)
                raise Thor::Error.new("Unable to locate Lanes environment.\nDoes ./lib/*/extension.rb exist?") if should_raise
                return nil
            end
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lanes-0.1.0 lib/lanes/command.rb