Module: Graphiti::ActiveGraph::ResourceInstanceMethods

Defined in:
lib/graphiti/active_graph/resource.rb

Instance Method Summary collapse

Instance Method Details

#extra_attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/graphiti/active_graph/resource.rb', line 37

def extra_attribute?(name)
  self.class.extra_attribute?(name)
end

#relation_resource?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/graphiti/active_graph/resource.rb', line 33

def relation_resource?
  self.class.relation_resource?
end

#resolve(scope) ⇒ Object



45
46
47
# File 'lib/graphiti/active_graph/resource.rb', line 45

def resolve(scope)
  adapter.resolve(scope, relation_resource?)
end

#sideload_name_arr(query) ⇒ Object



41
42
43
# File 'lib/graphiti/active_graph/resource.rb', line 41

def sideload_name_arr(query)
  query.sideloads.keys.map(&:to_sym)
end

#typecast(name, value, flag) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/graphiti/active_graph/resource.rb', line 49

def typecast(name, value, flag)
  att = get_attr!(name, flag, request: true)

  # in case of attribute is not declared on resource
  # do not throw error, return original value without typecast
  return value unless att

  type_name = att[:type]
  if flag == :filterable
    type_name = filters[name][:type]
  end
  type = Graphiti::Types[type_name]
  return if value.nil? && type[:kind] != "array"
  begin
    flag = :read if flag == :readable
    flag = :write if flag == :writable
    flag = :params if [:sortable, :filterable].include?(flag)
    type[flag][value]
  rescue => e
    raise Errors::TypecastFailed.new(self, name, value, e, type_name)
  end
end