Module: Cloudkeeper::Entities::Convertables::Convertable
- Included in:
- ImageFile
- Defined in:
- lib/cloudkeeper/entities/convertables/convertable.rb
Constant Summary
collapse
- CONVERT_OUTPUT_FORMATS =
%i[raw qcow2 vmdk vdi].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/cloudkeeper/entities/convertables/convertable.rb', line 24
def method_missing(method, *arguments, &block)
result = method.to_s.match(format_regex)
if result && result[:format]
return self if format.to_sym == result[:format].to_sym
return convert result[:format]
end
super
end
|
Class Method Details
.included(base) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/cloudkeeper/entities/convertables/convertable.rb', line 9
def self.included(base)
raise Cloudkeeper::Errors::Convertables::ConvertabilityError, "#{base.inspect} cannot become a convertable" \
unless base.method_defined?(:file) && base.method_defined?(:format)
super
end
|
Instance Method Details
16
17
18
|
# File 'lib/cloudkeeper/entities/convertables/convertable.rb', line 16
def convert_output_formats
CONVERT_OUTPUT_FORMATS
end
|
20
21
22
|
# File 'lib/cloudkeeper/entities/convertables/convertable.rb', line 20
def format_regex
/^to_(?<format>#{convert_output_formats.join('|')})$/
end
|
#respond_to_missing?(method) ⇒ Boolean
34
35
36
|
# File 'lib/cloudkeeper/entities/convertables/convertable.rb', line 34
def respond_to_missing?(method, *)
method =~ format_regex || super
end
|