Class: Tito::Admin::Scope
- Inherits:
-
Object
- Object
- Tito::Admin::Scope
- Defined in:
- lib/tito/admin/scope.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
-
#resource_class ⇒ Object
readonly
Returns the value of attribute resource_class.
Instance Method Summary collapse
- #collection_path(suffix: nil) ⇒ Object
- #connection ⇒ Object
-
#initialize(client:, account:, event: nil, resource_class:, parent_id: nil) ⇒ Scope
constructor
A new instance of Scope.
- #member_path(id_or_slug) ⇒ Object
- #nested_scope(child_class, parent_id:) ⇒ Object
- #request(method, path, params: {}, body: {}) ⇒ Object
Constructor Details
#initialize(client:, account:, event: nil, resource_class:, parent_id: nil) ⇒ Scope
Returns a new instance of Scope.
6 7 8 9 10 11 12 13 |
# File 'lib/tito/admin/scope.rb', line 6 def initialize(client:, account:, event: nil, resource_class:, parent_id: nil) @client = client @account = account @event = event @resource_class = resource_class @parent_id = parent_id validate! end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
4 5 6 |
# File 'lib/tito/admin/scope.rb', line 4 def account @account end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/tito/admin/scope.rb', line 4 def client @client end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
4 5 6 |
# File 'lib/tito/admin/scope.rb', line 4 def event @event end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
4 5 6 |
# File 'lib/tito/admin/scope.rb', line 4 def parent_id @parent_id end |
#resource_class ⇒ Object (readonly)
Returns the value of attribute resource_class.
4 5 6 |
# File 'lib/tito/admin/scope.rb', line 4 def resource_class @resource_class end |
Instance Method Details
#collection_path(suffix: nil) ⇒ Object
19 20 21 22 |
# File 'lib/tito/admin/scope.rb', line 19 def collection_path(suffix: nil) base = interpolate(resource_class.path_template) suffix ? "#{base}#{suffix}" : base end |
#connection ⇒ Object
15 16 17 |
# File 'lib/tito/admin/scope.rb', line 15 def connection client.connection end |
#member_path(id_or_slug) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/tito/admin/scope.rb', line 24 def member_path(id_or_slug) if resource_class.member_path_template interpolate(resource_class.member_path_template, id_or_slug: id_or_slug) else "#{collection_path}/#{id_or_slug}" end end |
#nested_scope(child_class, parent_id:) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/tito/admin/scope.rb', line 32 def nested_scope(child_class, parent_id:) self.class.new( client: client, account: account, event: event, resource_class: child_class, parent_id: parent_id ) end |
#request(method, path, params: {}, body: {}) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/tito/admin/scope.rb', line 42 def request(method, path, params: {}, body: {}) case method when :get then connection.get(path, params: params) when :post then connection.post(path, body: body) when :patch then connection.patch(path, body: body) when :delete then connection.delete(path) end end |