Module: QuickApi::Mongoid
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/quick_api/mongoid.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#to_api(options = {relations: true}, result = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/quick_api/mongoid.rb', line 57 def to_api( = {relations: true}, result = {}) if [:fields] api_fields = [:fields] else api_fields = self.quick_api_attributes.nil? ? [] : self.quick_api_attributes end api_fields.each do |api_field| begin if (self.send(api_field)).class == Paperclip::Attachment picture_styles = [] self.send(api_field).styles.each {|style| picture_styles << style[0]} result[api_field] = {original: "http://#{ActionMailer::Base.[:host]}#{self.send(api_field).url}", styles: picture_styles} else begin result[api_field] = self.send(api_field) rescue raise "The field #{api_field} don't exist in this Model" end end rescue begin result[api_field] = self.send(api_field) rescue raise "The field #{api_field} don't exist in this Model" end end end # if self.quick_api_methods # result = api_method_options(result, self.quick_api_methods) # end if [:relations] == true result = (result, self.quick_api_has_many) if self.quick_api_has_many result = (result, self.quick_api_belongs_to) if self.quick_api_belongs_to result = (result, self.quick_api_has_one) if self.quick_api_has_one result = (result, self.quick_api_has_and_belongs_to_many) if self.quick_api_has_and_belongs_to_many result = (result, self.) if self. result = (result, self.) if self. result = (result, self.) if self. end result = (result, ) return result end |