Class: Cloudflare::Relation
- Inherits:
-
Object
- Object
- Cloudflare::Relation
- Defined in:
- lib/cloudflare/relation.rb,
sig/cloudflare/relation.rbs
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
- #all(**params) ⇒ Array[Resource]
- #create(**attrs) ⇒ Resource
- #find(id) ⇒ Resource
-
#initialize(parent:, model:) ⇒ Relation
constructor
A new instance of Relation.
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) ⇒ Array[Resource]
15 |
# File 'lib/cloudflare/relation.rb', line 15 def all(**params) = @model.all(**child_scope, **params) |
#create(**attrs) ⇒ Resource
16 |
# File 'lib/cloudflare/relation.rb', line 16 def create(**attrs) = @model.create(**child_scope, **attrs) |
#find(id) ⇒ Resource
17 |
# File 'lib/cloudflare/relation.rb', line 17 def find(id) = @model.find(id, **child_scope) |