Class: Tailor::Configuration::Style

Inherits:
Object
  • Object
show all
Defined in:
lib/tailor/configuration/style.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStyle

Sets up default values.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tailor/configuration/style.rb', line 54

def initialize
  allow_camel_case_methods(false, level: :error)
  allow_conditional_parentheses(false, level: :warn)
  allow_hard_tabs(false, level: :error)
  allow_screaming_snake_case_classes(false, level: :error)
  allow_trailing_line_spaces(false, level: :error)
  allow_unnecessary_interpolation(false, level: :warn)
  allow_unnecessary_double_quotes(false, level: :warn)
  allow_invalid_ruby(false, level: :warn)
  indentation_spaces(2, level: :error)
  max_code_lines_in_class(300, level: :error)
  max_code_lines_in_method(30, level: :error)
  max_line_length(80, level: :error)
  spaces_after_comma(1, level: :error)
  spaces_after_conditional(1, level: :error)
  spaces_after_lbrace(1, level: :error)
  spaces_after_lbracket(0, level: :error)
  spaces_after_lparen(0, level: :error)
  spaces_before_comma(0, level: :error)
  spaces_before_lbrace(1, level: :error)
  spaces_before_rbrace(1, level: :error)
  spaces_before_rbracket(0, level: :error)
  spaces_before_rparen(0, level: :error)
  spaces_in_empty_braces(0, level: :error)
  trailing_newlines(1, level: :error)
end

Class Method Details

.define_property(name) ⇒ Object

Adds a style property to a Style object. If you’re planning on creating your own Ruler, you need to register the property here.

Defines a method from name that takes 2 parameters: value and options. value is the value to use for the Ruler of the same name for checking style. options can include anything that’s necessary for style checking. A :level option key is used to determine the Problem level:

  • :error results in a exit status of 1.

  • :warn results in an exit status of 0, but gets printed in the report.

Example:

Tailor::Configuration::Style.define_property(:my_style_property)
style = Tailor::Configuration::Style.new
style.my_style_property(100, level: :warn)


21
22
23
24
25
26
# File 'lib/tailor/configuration/style.rb', line 21

def self.define_property(name)
  define_method(name) do |value, *options|
    options = options.first || { level: :error }
    instance_variable_set("@#{name}".to_sym, [value, options])
  end
end

Instance Method Details

#eachObject

Yields each property and values.



93
94
95
96
97
# File 'lib/tailor/configuration/style.rb', line 93

def each
  to_hash.each do |property, values|
    yield property, values
  end
end

#to_hashHash

Returns the current style as a Hash.

Returns:

  • (Hash)


84
85
86
87
88
89
90
# File 'lib/tailor/configuration/style.rb', line 84

def to_hash
  instance_variables.inject({}) do |result, ivar|
    result[ivar.to_s.sub(/@/, '').to_sym] = instance_variable_get(ivar)

    result
  end
end