Module: Mxrb::RubyApp::Registry

Defined in:
lib/mxrb/ruby_app.rb

Overview

Per-process registry populated by conventional app/**/*.rb files.

Constant Summary collapse

ADAPTER_KINDS =
%i[
  app_service web_service import_xml import_mapping export_mapping document
].freeze

Class Method Summary collapse

Class Method Details

.adaptersObject



160
# File 'lib/mxrb/ruby_app.rb', line 160

def adapters = all(:adapter)

.all(kind) ⇒ Object



147
# File 'lib/mxrb/ruby_app.rb', line 147

def all(kind) = collection(kind).dup.freeze

.collection(kind) ⇒ Object



177
178
179
180
181
182
183
# File 'lib/mxrb/ruby_app.rb', line 177

def collection(kind)
  reset! unless defined?(@records) && @records
  {
    record: @records, service: @services, page: @pages, adapter: @adapters,
    java_custom_action: @java_custom_actions
  }.fetch(kind)
end

.fetch(kind, name) ⇒ Object



146
# File 'lib/mxrb/ruby_app.rb', line 146

def fetch(kind, name) = collection(kind)[name]

.java_custom_actionsObject



175
# File 'lib/mxrb/ruby_app.rb', line 175

def java_custom_actions = all(:java_custom_action)

.register(kind, name, implementation) ⇒ Object



142
143
144
# File 'lib/mxrb/ruby_app.rb', line 142

def register(kind, name, implementation)
  collection(kind)[name] = implementation
end

.register_adapter(kind, implementation = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


149
150
151
152
153
154
155
156
157
158
# File 'lib/mxrb/ruby_app.rb', line 149

def register_adapter(kind, implementation = nil, &block)
  key = kind.to_sym
  raise ArgumentError, "unsupported Ruby adapter #{kind}" unless ADAPTER_KINDS.include?(key)

  callback = implementation || block
  raise ArgumentError, 'adapter must respond to call' unless callback.respond_to?(:call)

  register(:adapter, key, callback)
  callback
end

.register_java_custom_action(name, implementation = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/mxrb/ruby_app.rb', line 162

def register_java_custom_action(name, implementation = nil, &block)
  qualified_name = name.to_s
  unless qualified_name.match?(/\A[A-Za-z_]\w*\.[A-Za-z_]\w*\z/)
    raise ArgumentError, "Java Custom Action name must be qualified as Module.Action: #{name}"
  end

  callback = implementation || block
  raise ArgumentError, 'Java Custom Action adapter must respond to call' unless callback.respond_to?(:call)

  register(:java_custom_action, qualified_name, callback)
  callback
end

.reset!Object



134
135
136
137
138
139
140
# File 'lib/mxrb/ruby_app.rb', line 134

def reset!
  @records = {}
  @services = {}
  @pages = {}
  @adapters = {}
  @java_custom_actions = {}
end