Class: Fera::Media
- Includes:
- BelongsToCustomer, BelongsToOrder, BelongsToProduct, BelongsToReview, BelongsToSubmission, HasSubject
- Defined in:
- lib/fera/models/media.rb
Instance Attribute Summary
Attributes inherited from Base
#last_response, #last_response_body, #last_response_exception, #last_response_message, #options
Class Method Summary collapse
Instance Method Summary collapse
- #file=(val) ⇒ Object
- #is_photo? ⇒ Boolean (also: #photo?)
- #is_video? ⇒ Boolean (also: #video?)
Methods included from BelongsToOrder
#external_order_id=, #order, #order=, #order_id=, #reload
Methods included from BelongsToSubmission
Methods included from BelongsToReview
Methods included from BelongsToProduct
Methods included from BelongsToCustomer
#customer, #customer=, #customer_id=, #external_customer_id=
Methods included from HasSubject
#for_product?, #for_store?, #product
Methods inherited from Base
api_key, api_key=, belongs_to, belongs_tos, #clone_selected_fields, #clone_with_nil, #create, create, #create!, create!, #created_at=, #destroy!, find_every, find_one, find_single, has_many, has_manys, has_one, has_ones, headers, headers=, #initialize, #known_attribute?, #load, #method_missing, new_element_path, order, #respond_to_missing?, #save, #save!, #set_last_response, #update, #update!, #updated_at=, #valid?
Constructor Details
This class inherits a constructor from Fera::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Fera::Base
Class Method Details
.instantiate_record(record, prefix_options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fera/models/media.rb', line 13 def instantiate_record(record, = {}) new_klass = if record['type'] == 'video' Video else Photo end new_klass.new(record, record['id'].present?).tap do |resource| resource. = end end |
Instance Method Details
#file=(val) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fera/models/media.rb', line 35 def file=(val) if val.is_a?(File) file_name = File.basename(val.path) mime_type_group = type == 'video' ? 'video' : 'image' self.attributes['file'] = { 'name' => File.basename(file_name), 'data' => "data:#{ mime_type_group }/#{ file_name.split('.').last };base64,#{ Base64.encode64(val.read) }", } else self.attributes['file'] = val end end |
#is_photo? ⇒ Boolean Also known as: photo?
30 31 32 |
# File 'lib/fera/models/media.rb', line 30 def is_photo? type.to_s == 'photo' end |
#is_video? ⇒ Boolean Also known as: video?
25 26 27 |
# File 'lib/fera/models/media.rb', line 25 def is_video? type.to_s == 'video' end |