Class: Cloudflare::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudflare/relation.rb

Overview

A scoped accessor for a nested REST collection. Created via the ‘has_many` macro on a parent Resource. Forwards `.all`, `.create`, `.find` to the child model with the parent’s scope (plus parent id) auto-injected.

meeting.participants.all                    # GET .../meetings/{id}/participants
meeting.participants.create(name: "Alice")  # POST .../meetings/{id}/participants
meeting.participants.find("p-1")            # GET .../meetings/{id}/participants/p-1

Instance Method Summary collapse

Constructor Details

#initialize(parent:, model:) ⇒ Relation

Returns a new instance of Relation.



10
11
12
13
# File 'lib/cloudflare/relation.rb', line 10

def initialize(parent:, model:)
  @parent = parent
  @model  = model
end

Instance Method Details

#all(**params) ⇒ Object



15
# File 'lib/cloudflare/relation.rb', line 15

def all(**params)    = @model.all(**child_scope, **params)

#create(**attrs) ⇒ Object



16
# File 'lib/cloudflare/relation.rb', line 16

def create(**attrs)  = @model.create(**child_scope, **attrs)

#find(id) ⇒ Object



17
# File 'lib/cloudflare/relation.rb', line 17

def find(id)         = @model.find(id, **child_scope)