Class: Apiwork::Adapter::Capability::Contract::Scope

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#actionsHash{Symbol => Resource::Action} (readonly)

The actions for this scope.

Returns:

  • (Hash{Symbol => Resource::Action})


17
18
19
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 17

def actions
  @actions
end

#representation_classObject (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.

Parameters:

  • name (Symbol)

    The action name.

Returns:

  • (Boolean)


56
57
58
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 56

def action?(name)
  actions.key?(name.to_sym)
end

#associationsHash{Symbol => Representation::Association}

The associations for this scope.

Returns:



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

#attributesHash{Symbol => Representation::Attribute}

The attributes for this scope.

Returns:



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_actionsHash{Symbol => Resource::Action}

The collection actions for this scope.

Returns:

  • (Hash{Symbol => Resource::Action})


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_actionsHash{Symbol => Resource::Action}

The CRUD actions for this scope.

Returns:

  • (Hash{Symbol => Resource::Action})


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_attributesArray<Representation::Attribute>

The filterable attributes for this scope.

Returns:



64
65
66
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 64

def filterable_attributes
  @filterable_attributes ||= attributes.values.select(&:filterable?)
end

#member_actionsHash{Symbol => Resource::Action}

The member actions for this scope.

Returns:

  • (Hash{Symbol => Resource::Action})


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_keyRepresentation::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_attributesArray<Representation::Attribute>

The sortable attributes for this scope.

Returns:



72
73
74
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 72

def sortable_attributes
  @sortable_attributes ||= attributes.values.select(&:sortable?)
end

#writable_attributesArray<Representation::Attribute>

The writable attributes for this scope.

Returns:



80
81
82
# File 'lib/apiwork/adapter/capability/contract/scope.rb', line 80

def writable_attributes
  @writable_attributes ||= attributes.values.select(&:writable?)
end