Class: Yodo::AMS

Inherits:
Object
  • Object
show all
Defined in:
lib/yodo/ams.rb

Class Method Summary collapse

Class Method Details

.analyze(*args) ⇒ Object

Takes one or more descendants of ActiveModel::Serializer and returns hash of serializers to results of analysis. Currently the only key in each serializer’s results is :suggested_includes which is a hash representing the includes that could perhaps be used to avoid n+1 queries or an empty array.



17
18
19
20
21
22
23
24
# File 'lib/yodo/ams.rb', line 17

def analyze(*args)
  args.pop if args.last.is_a?(Hash)
  serializer_to_results = {}        
  args.each do |serializer|
    serializer_to_results[serializer] = {:suggested_includes => find_includes(serializer)}
  end
  serializer_to_results
end

.analyze_allObject

Eager loads all Rails’ classes to get list of all descendants of ActiveModel::Serializer. Then returns hash of serializers to results of analysis. Currently the only key in each serializer’s results is :suggested_includes which is a hash representing the includes that should be done for each ActiveModel::Serializer or an empty array.



8
9
10
11
# File 'lib/yodo/ams.rb', line 8

def analyze_all
  Rails.application.eager_load!
  analyze(*ActiveModel::Serializer.descendants)
end