Class: LintTrappings::Application Abstract
- Inherits:
-
Object
- Object
- LintTrappings::Application
- Defined in:
- lib/lint_trappings/application.rb
Overview
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
-
.class_attribute(attr_name) ⇒ Object
Define an application configuration attribute.
Instance Method Summary collapse
-
#base_configuration ⇒ LintTrappings::Configuration
Base configuration which all other configurations extend (can be empty if desired).
-
#configuration_file_names ⇒ String
Configuration file names to look for, in order of precedence (first one found wins).
-
#document_class ⇒ Class
Class to use when loading/parsing documents.
-
#executable_name ⇒ String
Name of the application executable.
-
#file_extensions ⇒ String
List of file extensions the application can lint.
-
#home_url ⇒ String
URL of the application’s home page.
-
#initialize(output) ⇒ Application
constructor
A new instance of Application.
-
#issues_url ⇒ String
URL of the application’s issue and bug reports page.
-
#linter_base_class ⇒ Class
Base class of all linters for this application.
-
#linters_directory ⇒ String
Directory prefix where gem stores built-in linters.
-
#name ⇒ String
Proper name of this application.
- #run(options = {}) ⇒ Object
-
#version ⇒ String
Application version.
Constructor Details
#initialize(output) ⇒ Application
Returns a new instance of Application.
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 = (class << self; self; end) .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_configuration ⇒ LintTrappings::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.
57 |
# File 'lib/lint_trappings/application.rb', line 57 class_attribute :base_configuration |
#configuration_file_names ⇒ String
Returns 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_class ⇒ Class
Returns Class to use when loading/parsing documents.
79 |
# File 'lib/lint_trappings/application.rb', line 79 class_attribute :document_class |
#executable_name ⇒ String
Returns Name of the application executable.
49 |
# File 'lib/lint_trappings/application.rb', line 49 class_attribute :executable_name |
#file_extensions ⇒ String
Returns List of file extensions the application can lint.
64 |
# File 'lib/lint_trappings/application.rb', line 64 class_attribute :file_extensions |
#home_url ⇒ String
Returns URL of the application’s home page.
67 |
# File 'lib/lint_trappings/application.rb', line 67 class_attribute :home_url |
#issues_url ⇒ String
Returns 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_class ⇒ Class
Returns Base class of all linters for this application.
76 |
# File 'lib/lint_trappings/application.rb', line 76 class_attribute :linter_base_class |
#linters_directory ⇒ String
Returns Directory prefix where gem stores built-in linters.
73 |
# File 'lib/lint_trappings/application.rb', line 73 class_attribute :linters_directory |
#name ⇒ String
Returns 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( = {}) @output.color_enabled = .fetch(:color, @output.tty?) config = load_configuration() command = create_command([:command]).new(self, config, , @output) command.run end |
#version ⇒ String
Returns Application version.
52 |
# File 'lib/lint_trappings/application.rb', line 52 class_attribute :version |