Module: Spree::AgentTools::MembershipMap

Defined in:
lib/spree/agent_tools/membership_map.rb

Overview

The parents a product can belong to: categories, collections, catalogs, price lists — whatever the Admin API exposes its nested products surface for.

A contract like ResourceMap: core declares the shape, and spree_api fills it from the controllers that adopt the membership concern, so a parent that adopts it later is curated without a new tool.

Defined Under Namespace

Classes: Entry

Class Method Summary collapse

Class Method Details

.all ⇒ Array<Entry>

Returns:



17
18
19
20
# File 'lib/spree/agent_tools/membership_map.rb', line 17

def all
  derive!
  entries.values
end

.derive! ⇒ Object

Filled on first read rather than at boot: deriving it loads every admin controller, and a developer who never runs an agent should not pay that on each code reload.



46
47
48
49
50
51
# File 'lib/spree/agent_tools/membership_map.rb', line 46

def derive!
  return if @derived

  @derived = true
  Spree::Api::AgentMembershipMap.install if defined?(Spree::Api::AgentMembershipMap)
end

.find(target) ⇒ Entry?

Parameters:

  • target (String, Symbol) —

    'category', 'price_list', …

Returns:



24
25
26
27
# File 'lib/spree/agent_tools/membership_map.rb', line 24

def find(target)
  derive!
  entries[target.to_s]
end

.register(target:, permission:, api_path: nil) ⇒ Object



34
35
36
37
# File 'lib/spree/agent_tools/membership_map.rb', line 34

def register(target:, permission:, api_path: nil)
  entries[target.to_s] = Entry.new(target: target.to_s, permission: permission,
                                   api_path: api_path)
end

.reset! ⇒ Object



39
40
41
# File 'lib/spree/agent_tools/membership_map.rb', line 39

def reset!
  @entries = {}
end

.targets ⇒ Array<String>

Returns:

  • (Array<String>)


30
31
32
# File 'lib/spree/agent_tools/membership_map.rb', line 30

def targets
  all.map(&:target).sort
end