Module: GraphqlLazyLoad::ObjectHelper

Defined in:
lib/graphql_lazy_load/object_helper.rb

Instance Method Summary collapse

Instance Method Details

#lazy_load_association(method, association: method, &block) ⇒ Object



13
14
15
16
17
18
19
20
# 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) ⇒ Object



5
6
7
8
9
10
11
# 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