module GraphqlLazyLoad::ObjectHelper

Public Instance Methods

lazy_load_association(method, association: method, &block) click to toggle source
# File lib/graphql_lazy_load/object_helper.rb, line 13
def lazy_load_association(method, association: method, &block)
  define_method(method) do |**params|
    return ActiveRecordRelation.new(self, association, **params) unless block
    ActiveRecordRelation.new(self, association, **params) do |*options|
      instance_exec(*options, &block)
    end
  end
end
lazy_load_custom(method, value, default_value: nil, &block) click to toggle source
# File lib/graphql_lazy_load/object_helper.rb, line 5
def lazy_load_custom(method, value, default_value: nil, &block)
  define_method(method) do |**params|
    Custom.new(self, method, object.send(value), params.merge(default_value: default_value)) do |*options|
      instance_exec(*options, &block)
    end
  end
end