Class: JsonApiModel::ResultSet

Inherits:
Object
  • Object
show all
Defined in:
lib/json_api_model/result_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_result_set, model_class) ⇒ ResultSet

Returns a new instance of ResultSet.



3
4
5
6
7
8
# File 'lib/json_api_model/result_set.rb', line 3

def initialize( client_result_set, model_class )
  @set = client_result_set.clone
  @set.map! do | resource |
    model_class.new_from_client( resource )
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



28
29
30
# File 'lib/json_api_model/result_set.rb', line 28

def method_missing( m, *args, &block )
  @set.send m, *args, &block
end

Instance Method Details

#as_json(opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/json_api_model/result_set.rb', line 10

def as_json( opts = {} )
  if block_given?
    yield @set, meta
  else
    { data: @set.map(&:as_json),
      meta: meta
    }
  end
end

#metaObject



24
25
26
# File 'lib/json_api_model/result_set.rb', line 24

def meta
  @set.meta.attributes
end

#preload(*args) ⇒ Object



20
21
22
# File 'lib/json_api_model/result_set.rb', line 20

def preload( *args )
  JsonApiModel::Associations::Preloader.preload( self, *args )
end