Class: WarningSigns::Handler
- Inherits:
-
Object
- Object
- WarningSigns::Handler
- Defined in:
- lib/warning_signs/handler.rb
Instance Attribute Summary collapse
-
#backtrace_lines ⇒ Object
Returns the value of attribute backtrace_lines.
-
#category_matcher ⇒ Object
Returns the value of attribute category_matcher.
-
#environments ⇒ Object
Returns the value of attribute environments.
-
#message_formatters ⇒ Object
Returns the value of attribute message_formatters.
-
#only_except ⇒ Object
Returns the value of attribute only_except.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #category_match?(category) ⇒ Boolean
- #enabled_for_rails? ⇒ Boolean
- #enabled_for_ruby? ⇒ Boolean
- #environment(current: nil) ⇒ Object
-
#initialize(behavior: nil, behaviors: [], environment: nil, except: [], only: [], source: "any", environments: [], ruby_warnings: {}, message_formatter: nil, message_formatters: []) ⇒ Handler
constructor
A new instance of Handler.
- #known_source?(deprecation_source) ⇒ Boolean
- #match?(deprecation) ⇒ Boolean
- #message_formatter_for(behavior) ⇒ Object
- #pattern_match?(message) ⇒ Boolean
- #source_match?(deprecation_source) ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(behavior: nil, behaviors: [], environment: nil, except: [], only: [], source: "any", environments: [], ruby_warnings: {}, message_formatter: nil, message_formatters: []) ⇒ Handler
Returns a new instance of Handler.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/warning_signs/handler.rb', line 10 def initialize( behavior: nil, behaviors: [], environment: nil, except: [], only: [], source: "any", environments: [], ruby_warnings: {}, message_formatter: nil, message_formatters: [] ) @only_except = OnlyExcept.new( only: only.map { Pattern.for(_1) }, except: except.map { Pattern.for(_1) } ) @environments = environments.map { Environment.new(**_1.symbolize_keys) } if environment.present? @environments << Environment.new( environment: environment, behaviors: behaviors, behavior: behavior ) end @source = source.to_s.downcase.inquiry @category_matcher = RubyCategoryMatcher.new(**ruby_warnings.symbolize_keys) @message_formatters = MessageFormatterList.new( message_formatters: , message_formatter: ) raise InvalidHandlerError unless valid? end |
Instance Attribute Details
#backtrace_lines ⇒ Object
Returns the value of attribute backtrace_lines.
3 4 5 |
# File 'lib/warning_signs/handler.rb', line 3 def backtrace_lines @backtrace_lines end |
#category_matcher ⇒ Object
Returns the value of attribute category_matcher.
3 4 5 |
# File 'lib/warning_signs/handler.rb', line 3 def category_matcher @category_matcher end |
#environments ⇒ Object
Returns the value of attribute environments.
3 4 5 |
# File 'lib/warning_signs/handler.rb', line 3 def environments @environments end |
#message_formatters ⇒ Object
Returns the value of attribute message_formatters.
3 4 5 |
# File 'lib/warning_signs/handler.rb', line 3 def @message_formatters end |
#only_except ⇒ Object
Returns the value of attribute only_except.
3 4 5 |
# File 'lib/warning_signs/handler.rb', line 3 def only_except @only_except end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/warning_signs/handler.rb', line 3 def source @source end |
Class Method Details
.from_hash(hash) ⇒ Object
6 7 8 |
# File 'lib/warning_signs/handler.rb', line 6 def self.from_hash(hash) new(**hash.symbolize_keys) end |
Instance Method Details
#category_match?(category) ⇒ Boolean
66 67 68 |
# File 'lib/warning_signs/handler.rb', line 66 def category_match?(category) category_matcher.match?(category) end |
#enabled_for_rails? ⇒ Boolean
79 80 81 |
# File 'lib/warning_signs/handler.rb', line 79 def enabled_for_rails? source.rails? || source.all? end |
#enabled_for_ruby? ⇒ Boolean
75 76 77 |
# File 'lib/warning_signs/handler.rb', line 75 def enabled_for_ruby? source.ruby? || source.all? end |
#environment(current: nil) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/warning_signs/handler.rb', line 83 def environment(current: nil) current ||= Rails.env environments.find { _1.environment == current } || environments.find { _1.environment.all? } || environments.find { _1.environment.other? } end |
#known_source?(deprecation_source) ⇒ Boolean
52 53 54 |
# File 'lib/warning_signs/handler.rb', line 52 def known_source?(deprecation_source) deprecation_source.in?(%w[ruby rails]) end |
#match?(deprecation) ⇒ Boolean
60 61 62 63 64 |
# File 'lib/warning_signs/handler.rb', line 60 def match?(deprecation) source_match?(deprecation.source) && pattern_match?(deprecation.) && category_match?(deprecation.category) end |
#message_formatter_for(behavior) ⇒ Object
43 44 45 46 |
# File 'lib/warning_signs/handler.rb', line 43 def (behavior) .behavior_match(behavior) || MessageFormatter::Text.new end |
#pattern_match?(message) ⇒ Boolean
56 57 58 |
# File 'lib/warning_signs/handler.rb', line 56 def pattern_match?() only_except.only_except_match?() end |
#source_match?(deprecation_source) ⇒ Boolean
70 71 72 73 |
# File 'lib/warning_signs/handler.rb', line 70 def source_match?(deprecation_source) return known_source?(deprecation_source) if source.any? source == deprecation_source end |
#valid? ⇒ Boolean
48 49 50 |
# File 'lib/warning_signs/handler.rb', line 48 def valid? only_except.valid? end |