Exception: Graphiti::Errors::AttributeError

Inherits:
Base
  • Object
show all
Defined in:
lib/graphiti/errors.rb

Direct Known Subclasses

InvalidAttributeAccess, UnknownAttribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, name, flag, **opts) ⇒ AttributeError

Returns a new instance of AttributeError.



336
337
338
339
340
341
# File 'lib/graphiti/errors.rb', line 336

def initialize(resource, name, flag, **opts)
  @resource = resource
  @name = name
  @flag = flag
  @request = opts[:request] || false
end

Instance Attribute Details

#existsObject (readonly)

Returns the value of attribute exists.



329
330
331
# File 'lib/graphiti/errors.rb', line 329

def exists
  @exists
end

#flagObject (readonly)

Returns the value of attribute flag.



329
330
331
# File 'lib/graphiti/errors.rb', line 329

def flag
  @flag
end

#guardObject (readonly)

Returns the value of attribute guard.



329
330
331
# File 'lib/graphiti/errors.rb', line 329

def guard
  @guard
end

#nameObject (readonly)

Returns the value of attribute name.



329
330
331
# File 'lib/graphiti/errors.rb', line 329

def name
  @name
end

#requestObject (readonly)

Returns the value of attribute request.



329
330
331
# File 'lib/graphiti/errors.rb', line 329

def request
  @request
end

#resourceObject (readonly)

Returns the value of attribute resource.



329
330
331
# File 'lib/graphiti/errors.rb', line 329

def resource
  @resource
end

Instance Method Details

#actionObject



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/graphiti/errors.rb', line 343

def action
  if @request
    {
      sortable: "sort on",
      filterable: "filter on",
      readable: "read",
      writable: "write"
    }[@flag]
  else
    {
      sortable: "add sort",
      filterable: "add filter",
      readable: "read",
      writable: "write"
    }[@flag]
  end
end

#messageObject



370
371
372
# File 'lib/graphiti/errors.rb', line 370

def message
  "#{resource_name}: Tried to #{action} attribute #{@name.inspect}"
end

#resource_nameObject



361
362
363
364
365
366
367
368
# File 'lib/graphiti/errors.rb', line 361

def resource_name
  name = if @resource.is_a?(Graphiti::Resource)
    @resource.class.name
  else
    @resource.name
  end
  name || "AnonymousResourceClass"
end