Class: Apiwork::Adapter::Capability::Contract::Scope
- Inherits:
-
Object
- Object
- Apiwork::Adapter::Capability::Contract::Scope
- Defined in:
- lib/apiwork/adapter/capability/contract/scope.rb
Overview
Scope for capability contract builders.
Provides access to the representation and actions for this contract. Use this to query contract-specific state when building types.
Instance Attribute Summary collapse
-
#actions ⇒ Hash{Symbol => Resource::Action}
readonly
The actions for this scope.
- #representation_class ⇒ Object readonly
Instance Method Summary collapse
-
#action?(name) ⇒ Boolean
Whether this scope includes the given action.
-
#associations ⇒ Hash{Symbol => Representation::Association}
The associations for this scope.
-
#attributes ⇒ Hash{Symbol => Representation::Attribute}
The attributes for this scope.
-
#collection_actions ⇒ Hash{Symbol => Resource::Action}
The collection actions for this scope.
-
#crud_actions ⇒ Hash{Symbol => Resource::Action}
The CRUD actions for this scope.
-
#filterable_attributes ⇒ Array<Representation::Attribute>
The filterable attributes for this scope.
-
#initialize(representation_class, actions) ⇒ Scope
constructor
A new instance of Scope.
-
#member_actions ⇒ Hash{Symbol => Resource::Action}
The member actions for this scope.
-
#root_key ⇒ Representation::RootKey
The root key for this scope.
-
#sortable_attributes ⇒ Array<Representation::Attribute>
The sortable attributes for this scope.
-
#writable_attributes ⇒ Array<Representation::Attribute>
The writable attributes for this scope.
Constructor Details
#initialize(representation_class, actions) ⇒ Scope
Returns a new instance of Scope.
21 22 23 24 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 21 def initialize(representation_class, actions) @representation_class = representation_class @actions = actions end |
Instance Attribute Details
#actions ⇒ Hash{Symbol => Resource::Action} (readonly)
The actions for this scope.
17 18 19 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 17 def actions @actions end |
#representation_class ⇒ Object (readonly)
19 20 21 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 19 def representation_class @representation_class end |
Instance Method Details
#action?(name) ⇒ Boolean
Whether this scope includes the given action.
56 57 58 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 56 def action?(name) actions.key?(name.to_sym) end |
#associations ⇒ Hash{Symbol => Representation::Association}
The associations for this scope.
101 102 103 104 105 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 101 delegate :adapter_config, :associations, :attributes, :root_key, to: :representation_class |
#attributes ⇒ Hash{Symbol => Representation::Attribute}
The attributes for this scope.
101 102 103 104 105 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 101 delegate :adapter_config, :associations, :attributes, :root_key, to: :representation_class |
#collection_actions ⇒ Hash{Symbol => Resource::Action}
The collection actions for this scope.
30 31 32 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 30 def collection_actions @collection_actions ||= actions.select { |_name, action| action.collection? } end |
#crud_actions ⇒ Hash{Symbol => Resource::Action}
The CRUD actions for this scope.
46 47 48 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 46 def crud_actions @crud_actions ||= actions.select { |_name, action| action.crud? } end |
#filterable_attributes ⇒ Array<Representation::Attribute>
The filterable attributes for this scope.
64 65 66 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 64 def filterable_attributes @filterable_attributes ||= attributes.values.select(&:filterable?) end |
#member_actions ⇒ Hash{Symbol => Resource::Action}
The member actions for this scope.
38 39 40 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 38 def member_actions @member_actions ||= actions.select { |_name, action| action.member? } end |
#root_key ⇒ Representation::RootKey
The root key for this scope.
101 102 103 104 105 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 101 delegate :adapter_config, :associations, :attributes, :root_key, to: :representation_class |
#sortable_attributes ⇒ Array<Representation::Attribute>
The sortable attributes for this scope.
72 73 74 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 72 def sortable_attributes @sortable_attributes ||= attributes.values.select(&:sortable?) end |
#writable_attributes ⇒ Array<Representation::Attribute>
The writable attributes for this scope.
80 81 82 |
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 80 def writable_attributes @writable_attributes ||= attributes.values.select(&:writable?) end |