Class: XMP::Handler::File
- Inherits:
-
Object
- Object
- XMP::Handler::File
- Defined in:
- lib/xmp/handler/file.rb
Constant Summary collapse
- SUPPORTED =
[String, Pathname, ::File]
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
Instance Method Summary collapse
- #call(object) ⇒ Object
-
#initialize(*extensions, &callback) ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize(*extensions, &callback) ⇒ File
Returns a new instance of File.
8 9 10 11 |
# File 'lib/xmp/handler/file.rb', line 8 def initialize(*extensions, &callback) @extensions = extensions @callback = callback end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
6 7 8 |
# File 'lib/xmp/handler/file.rb', line 6 def callback @callback end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
6 7 8 |
# File 'lib/xmp/handler/file.rb', line 6 def extensions @extensions end |
Instance Method Details
#call(object) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/xmp/handler/file.rb', line 13 def call(object) return unless SUPPORTED.any? { |c| c === object } return unless path = Pathname(object) and extensions.include? path.extname.downcase return callback.call(object) if object.is_a? IO return path.open(&callback) if path.exist? and path.readable? raise XMP::Error, "cannot read file #{path}" end |