lib/her/model/relation.rb
# Fetch specific resource(s) by their ID
#
# @example
#   @user = User.find(1)
#   # Fetched via GET "/users/1"
#
# @example
#   @users = User.find([1, 2])
#   # Fetched via GET "/users/1" and GET "/users/2"
Fetch specific resource(s) by their ID
Fetch specific resource ( s ) by their ID
def find(*ids)
        params = @params.merge(ids.last.is_a?(Hash) ? ids.pop : {})
        ids = Array(params[@parent.primary_key]) if params.key?(@parent.primary_key)
        results = ids.flatten.compact.uniq.map do |id|
          resource = nil
          request_params = params.merge(
            :_method => @parent.method_for(:find),
            :_path => @parent.build_request_path(params.merge(@parent.primary_key => id))
          )
          @parent.request(request_params) do |parsed_data, response|
            if response.success?
              resource = @parent.new_from_parsed_data(parsed_data)
              resource.run_callbacks :find
            else
              return nil
            end
          end
          resource
        end
        ids.length > 1 || ids.first.is_a?(Array) ? results : results.first
      end
def find ( * ids ) params = @params . merge ( ids . last . is_a? ( Hash ) ? ids . pop : { } ) ids = Array ( params [ @parent . primary_key ] ) if params . key? ( @parent . primary_key ) results = ids . flatten . compact . uniq . map do | id | resource = nil request_params = params . merge ( :_method => @parent . method_for ( :find ) , :_path => @parent . build_request_path ( params . merge ( @parent . primary_key => id ) ) ) @parent . request ( request_params ) do | parsed_data , response | if response . success? resource = @parent . new_from_parsed_data ( parsed_data ) resource . run_callbacks :find else return nil end end resource end ids . length > 1 || ids . first . is_a? ( Array ) ? results : results . first end
Fetch specific resource(s) by their ID
Fetch specific resource ( s ) by their ID
ids
<not_specific>
example
@user = User.find(1) # Fetched via GET "/users/1"
@user = User . find ( 1 ) # Fetched via GET " / users / 1 "
example
@users = User.find([1, 2]) # Fetched via GET "/users/1" and GET "/users/2"
@users = User . find ( [ 1 2 ] ) # Fetched via GET " / users / 1 " and GET " / users / 2 "