Class: ROM::HTTP::Relation

Inherits:
Relation
  • Object
show all
Extended by:
Dry::Core::Cache, Initializer
Includes:
Enumerable
Defined in:
lib/rom/http/relation.rb

Overview

HTTP-specific relation extensions

Instance Method Summary collapse

Constructor Details

#initializeRelation

Returns a new instance of Relation.



25
26
27
28
29
30
31
32
# File 'lib/rom/http/relation.rb', line 25

def initialize(*)
  super

  raise(
    SchemaNotDefinedError,
    "You must define a schema for #{self.class.register_as} relation"
  ) unless schema?
end

Instance Method Details

#deleteObject

See Also:



80
81
82
# File 'lib/rom/http/relation.rb', line 80

def delete
  dataset.delete
end

#exclude(*names) ⇒ Object



48
49
50
# File 'lib/rom/http/relation.rb', line 48

def exclude(*names)
  with(schema: schema.exclude(*names.flatten))
end

#insert(*args) ⇒ Object Also known as: <<

See Also:



69
70
71
# File 'lib/rom/http/relation.rb', line 69

def insert(*args)
  with_transformation { dataset.insert(*args) }
end

#prefix(prefix) ⇒ Object



56
57
58
# File 'lib/rom/http/relation.rb', line 56

def prefix(prefix)
  with(schema: schema.prefix(prefix))
end

#primary_keyObject



34
35
36
37
38
39
40
41
42
# File 'lib/rom/http/relation.rb', line 34

def primary_key
  attribute = schema.find(&:primary_key?)

  if attribute
    attribute.alias || attribute.name
  else
    :id
  end
end

#project(*names) ⇒ Object



44
45
46
# File 'lib/rom/http/relation.rb', line 44

def project(*names)
  with(schema: schema.project(*names.flatten))
end

#rename(mapping) ⇒ Object



52
53
54
# File 'lib/rom/http/relation.rb', line 52

def rename(mapping)
  with(schema: schema.rename(mapping))
end

#to_aObject



64
65
66
# File 'lib/rom/http/relation.rb', line 64

def to_a
  with_transformation { super }
end

#update(*args) ⇒ Object

See Also:



75
76
77
# File 'lib/rom/http/relation.rb', line 75

def update(*args)
  with_transformation { dataset.update(*args) }
end

#wrap(prefix = dataset.name) ⇒ Object



60
61
62
# File 'lib/rom/http/relation.rb', line 60

def wrap(prefix = dataset.name)
  with(schema: schema.wrap(prefix))
end