lib/contentful_model/base.rb
#use method_missing to call fields on the model
use method_missing to call fields on the model
use method_missing to call fields on the model
def method_missing(method, *args, &block)
      result = fields[:"#{method.to_s.camelize(:lower)}"]
      if result.is_a?(Array)
        result.reject! {|r| r.is_a?(Contentful::Link) || (r.respond_to?(:invalid) && r.invalid?)}
      elsif result.is_a?(Contentful::Link)
        result = nil
      elsif result.respond_to?(:fields) && result.send(:fields).empty?
        result = nil
      elsif result.respond_to?(:invalid?) && result.invalid?
        result = nil
      end
      if result.nil?
        if self.class.return_nil_for_empty_attribute_fields && self.class.return_nil_for_empty_attribute_fields.include?(method)
          return nil
        else
          raise ContentfulModel::AttributeNotFoundError, "no attribute #{method} found"
        end
      else
        self.class.coerce_value(method, result)
      end
    end
def method_missing ( method , * args , & block ) result = fields [ :" #{ method . to_s . camelize ( :lower ) } " ] if result . is_a? ( Array ) result . reject! { | r | r . is_a? ( Contentful :: Link ) || ( r . respond_to? ( :invalid ) && r . invalid? ) } elsif result . is_a? ( Contentful :: Link ) result = nil elsif result . respond_to? ( :fields ) && result . send ( :fields ) . empty? result = nil elsif result . respond_to? ( :invalid? ) && result . invalid? result = nil end if result . nil? if self . class . return_nil_for_empty_attribute_fields && self . class . return_nil_for_empty_attribute_fields . include? ( method ) return nil else raise ContentfulModel :: AttributeNotFoundError , "no attribute #{method} found" end else self . class . coerce_value ( method , result ) end end
use method_missing to call fields on the model
use method_missing to call fields on the model
# we need to pull out any Contentful::Link references, and also things which don't have any fields at all # because they're newly created # if self.class.rescue_from_no_attribute_fields.member?() # end
method
<not_specific>
args
<not_specific>
block
<not_specific>