Class: MarkdownServer::CsvBrowser::AddonDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_server/csv_browser/addon_registry.rb

Overview

Holds one add-on’s declarative definition: its ‘actions` block and a set of `on :action_id` handler blocks. Created via the DSL inside `register`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ AddonDefinition

Returns a new instance of AddonDefinition.



10
11
12
13
14
# File 'lib/markdown_server/csv_browser/addon_registry.rb', line 10

def initialize(name)
  @name = name.to_sym
  @actions_block = nil
  @handlers = {}
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/markdown_server/csv_browser/addon_registry.rb', line 8

def name
  @name
end

Instance Method Details

#actions(&block) ⇒ Object



16
17
18
# File 'lib/markdown_server/csv_browser/addon_registry.rb', line 16

def actions(&block)
  @actions_block = block
end

#actions_for(ctx) ⇒ Object

Returns [{ id:, label:, enabled:, … }, …] for the given row context.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/markdown_server/csv_browser/addon_registry.rb', line 25

def actions_for(ctx)
  return [] unless @actions_block

  result = @actions_block.call(ctx)
  Array(result).map do |entry|
    h = entry.dup
    h[:id] = h[:id].to_sym
    h[:enabled] = h.key?(:enabled) ? !!h[:enabled] : true
    h
  end
end

#handler_for(action_id) ⇒ Object



37
38
39
# File 'lib/markdown_server/csv_browser/addon_registry.rb', line 37

def handler_for(action_id)
  @handlers[action_id.to_sym]
end

#on(action_id, &block) ⇒ Object



20
21
22
# File 'lib/markdown_server/csv_browser/addon_registry.rb', line 20

def on(action_id, &block)
  @handlers[action_id.to_sym] = block
end