Class: Troy::ExtensionMatcher
- Inherits:
-
Object
- Object
- Troy::ExtensionMatcher
- Defined in:
- lib/troy/extension_matcher.rb
Instance Attribute Summary collapse
-
#matchers ⇒ Object
readonly
Returns the value of attribute matchers.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#performed ⇒ Object
readonly
Returns the value of attribute performed.
Instance Method Summary collapse
- #default(&block) ⇒ Object
-
#initialize(path) ⇒ ExtensionMatcher
constructor
A new instance of ExtensionMatcher.
- #match ⇒ Object
- #on(extension, &block) ⇒ Object
Constructor Details
#initialize(path) ⇒ ExtensionMatcher
Returns a new instance of ExtensionMatcher.
7 8 9 10 |
# File 'lib/troy/extension_matcher.rb', line 7 def initialize(path) @path = path @matchers = {} end |
Instance Attribute Details
#matchers ⇒ Object (readonly)
Returns the value of attribute matchers.
5 6 7 |
# File 'lib/troy/extension_matcher.rb', line 5 def matchers @matchers end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/troy/extension_matcher.rb', line 5 def path @path end |
#performed ⇒ Object (readonly)
Returns the value of attribute performed.
5 6 7 |
# File 'lib/troy/extension_matcher.rb', line 5 def performed @performed end |
Instance Method Details
#default(&block) ⇒ Object
17 18 19 20 |
# File 'lib/troy/extension_matcher.rb', line 17 def default(&block) matchers["default"] = block self end |
#match ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/troy/extension_matcher.rb', line 22 def match matchers.each do |ext, handler| return handler.call if File.extname(path) == ext end matchers["default"]&.call end |
#on(extension, &block) ⇒ Object
12 13 14 15 |
# File 'lib/troy/extension_matcher.rb', line 12 def on(extension, &block) matchers[".#{extension}"] = block self end |