Class: LintTrappings::Application Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/lint_trappings/application.rb

Overview

This class is abstract.

Linter application superclass.

Implementors will subclass this and specify a number of high-level configuration options which will help the class run your custom application.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Application

Returns a new instance of Application.

Parameters:



82
83
84
# File 'lib/lint_trappings/application.rb', line 82

def initialize(output)
  @output = output
end

Class Method Details

.class_attribute(attr_name) ⇒ Object

Define an application configuration attribute.

This is intended to be used to make specifying the configuration for a LintTrappings application easy. It defines a class instance variable which is specified in the body of the class itself via DSL-like method call, and also defines a method so the value can be obtained from a single instance.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lint_trappings/application.rb', line 19

def self.class_attribute(attr_name)
  # Define DSL getter/setter
  metaclass = (class << self; self; end)
  metaclass.instance_eval do
    define_method(attr_name) do |*args|
      if args.any?
        instance_variable_set(:"@#{attr_name}", args.first)
      else
        value = instance_variable_get(:"@#{attr_name}")

        if value.nil?
          raise ApplicationConfigurationError,
                "`#{attr_name}` class attribute must be defined in #{self}!"
        end

        value
      end
    end
  end

  # Define method on the class
  define_method(attr_name) do
    self.class.send(attr_name)
  end
end

Instance Method Details

#base_configurationLintTrappings::Configuration

Returns Base configuration which all other configurations extend (can be empty if desired). This should be the same class as the configuration_class attribute.

Returns:

  • (LintTrappings::Configuration)

    Base configuration which all other configurations extend (can be empty if desired). This should be the same class as the configuration_class attribute.



57
# File 'lib/lint_trappings/application.rb', line 57

class_attribute :base_configuration

#configuration_file_namesString

Returns Configuration file names to look for, in order of precedence (first one found wins).

Returns:

  • (String)

    Configuration file names to look for, in order of precedence (first one found wins)



61
# File 'lib/lint_trappings/application.rb', line 61

class_attribute :configuration_file_names

#document_classClass

Returns Class to use when loading/parsing documents.

Returns:

  • (Class)

    Class to use when loading/parsing documents



79
# File 'lib/lint_trappings/application.rb', line 79

class_attribute :document_class

#executable_nameString

Returns Name of the application executable.

Returns:

  • (String)

    Name of the application executable



49
# File 'lib/lint_trappings/application.rb', line 49

class_attribute :executable_name

#file_extensionsString

Returns List of file extensions the application can lint.

Returns:

  • (String)

    List of file extensions the application can lint



64
# File 'lib/lint_trappings/application.rb', line 64

class_attribute :file_extensions

#home_urlString

Returns URL of the application’s home page.

Returns:

  • (String)

    URL of the application’s home page



67
# File 'lib/lint_trappings/application.rb', line 67

class_attribute :home_url

#issues_urlString

Returns URL of the application’s issue and bug reports page.

Returns:

  • (String)

    URL of the application’s issue and bug reports page



70
# File 'lib/lint_trappings/application.rb', line 70

class_attribute :issues_url

#linter_base_classClass

Returns Base class of all linters for this application.

Returns:

  • (Class)

    Base class of all linters for this application



76
# File 'lib/lint_trappings/application.rb', line 76

class_attribute :linter_base_class

#linters_directoryString

Returns Directory prefix where gem stores built-in linters.

Returns:

  • (String)

    Directory prefix where gem stores built-in linters



73
# File 'lib/lint_trappings/application.rb', line 73

class_attribute :linters_directory

#nameString

Returns Proper name of this application.

Returns:

  • (String)

    Proper name of this application



46
# File 'lib/lint_trappings/application.rb', line 46

class_attribute :name

#run(options = {}) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/lint_trappings/application.rb', line 86

def run(options = {})
  @output.color_enabled = options.fetch(:color, @output.tty?)
  config = load_configuration(options)

  command = create_command(options[:command]).new(self, config, options, @output)
  command.run
end

#versionString

Returns Application version.

Returns:

  • (String)

    Application version



52
# File 'lib/lint_trappings/application.rb', line 52

class_attribute :version