Class: Raif::ModelFileInput
- Inherits:
-
Object
- Object
- Raif::ModelFileInput
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/raif/model_file_input.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base64_data ⇒ Object
Returns the value of attribute base64_data.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#input ⇒ Object
Returns the value of attribute input.
-
#source_type ⇒ Object
Returns the value of attribute source_type.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #file_bytes ⇒ Object
-
#initialize(input: nil, url: nil) ⇒ ModelFileInput
constructor
A new instance of ModelFileInput.
- #inspect ⇒ Object
Constructor Details
#initialize(input: nil, url: nil) ⇒ ModelFileInput
Returns a new instance of ModelFileInput.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/raif/model_file_input.rb', line 12 def initialize(input: nil, url: nil) raise ArgumentError, "You must provide either an input or a URL" if input.blank? && url.blank? raise ArgumentError, "Provide either input or URL, not both" if input.present? && url.present? super(input: input, url: url) if url.present? @source_type = :url elsif input.present? @source_type = :file_content process_input! end unless valid? raise Raif::Errors::InvalidModelFileInputError, errors..join(", ") end end |
Instance Attribute Details
#base64_data ⇒ Object
Returns the value of attribute base64_data.
6 7 8 |
# File 'app/models/raif/model_file_input.rb', line 6 def base64_data @base64_data end |
#content_type ⇒ Object
Returns the value of attribute content_type.
6 7 8 |
# File 'app/models/raif/model_file_input.rb', line 6 def content_type @content_type end |
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'app/models/raif/model_file_input.rb', line 6 def filename @filename end |
#input ⇒ Object
Returns the value of attribute input.
6 7 8 |
# File 'app/models/raif/model_file_input.rb', line 6 def input @input end |
#source_type ⇒ Object
Returns the value of attribute source_type.
6 7 8 |
# File 'app/models/raif/model_file_input.rb', line 6 def source_type @source_type end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'app/models/raif/model_file_input.rb', line 6 def url @url end |
Instance Method Details
#file_bytes ⇒ Object
34 35 36 |
# File 'app/models/raif/model_file_input.rb', line 34 def file_bytes Base64.strict_decode64(base64_data) end |
#inspect ⇒ Object
30 31 32 |
# File 'app/models/raif/model_file_input.rb', line 30 def inspect "#<#{self.class.name} input=#{input.inspect} url=#{url.inspect} base64_data=#{base64_data&.truncate(20)} filename=#{filename.inspect} content_type=#{content_type.inspect} source_type=#{source_type.inspect}>" # rubocop:disable Layout/LineLength end |