module Aggro::BindingDSL
Public: Adds a DSL creating domain event bindings.
Public Instance Methods
bind(ref, filters: default_filters, to: nil, &block)
click to toggle source
# File lib/aggro/binding_dsl.rb, line 4 def bind(ref, filters: default_filters, to: nil, &block) if to bindings << Aggro.event_bus.subscribe(ref.id, self, to, filters) else bind_block ref, filters, &block end end
Private Instance Methods
bind_block(ref, filters, namespace = generate_namespace, &block)
click to toggle source
# File lib/aggro/binding_dsl.rb, line 14 def bind_block(ref, filters, namespace = generate_namespace, &block) new_methods = BlockHelper.method_definitions(&block) event_methods[namespace] = Set.new(new_methods) class_eval(&block) move_methods_to_namespace(new_methods, namespace) bindings << Aggro.event_bus.subscribe(ref.id, self, namespace, filters) end
bindings()
click to toggle source
# File lib/aggro/binding_dsl.rb, line 24 def bindings @bindings ||= [] end
default_filters()
click to toggle source
# File lib/aggro/binding_dsl.rb, line 28 def default_filters {} end
generate_namespace()
click to toggle source
# File lib/aggro/binding_dsl.rb, line 32 def generate_namespace [*('a'..'z')].sample(8).join end
move_methods_to_namespace(method_list, namespace)
click to toggle source
# File lib/aggro/binding_dsl.rb, line 36 def move_methods_to_namespace(method_list, namespace) class_eval do method_list.each do |method| alias_method "#{namespace}_#{method}", method remove_method method end end end