Class: AppBase::Registry::RegistryTable
- Inherits:
-
Object
- Object
- AppBase::Registry::RegistryTable
- Defined in:
- lib/appbase/registry.rb
Instance Method Summary collapse
- #contains_rpc_registry(item) ⇒ Object
- #each_crud(*models, &block) ⇒ Object
- #each_rpc(&block) ⇒ Object
-
#initialize ⇒ RegistryTable
constructor
A new instance of RegistryTable.
- #register_crud(model, crud) ⇒ Object
- #register_rpc(model, method_name, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ RegistryTable
Returns a new instance of RegistryTable.
28 29 30 31 |
# File 'lib/appbase/registry.rb', line 28 def initialize @rpc_methods = [] = [] end |
Instance Method Details
#contains_rpc_registry(item) ⇒ Object
33 34 35 |
# File 'lib/appbase/registry.rb', line 33 def contains_rpc_registry(item) !@rpc_methods.find{ |r| r[:model] == item[:model] && r[:method] == item[:method] }.nil? end |
#each_crud(*models, &block) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/appbase/registry.rb', line 57 def each_crud(*models, &block) models = models.flatten.map { |model| (model.instance_of?(Symbol) || model.instance_of?(String)) ? Object.const_get(model) : model } .each do |r| block.call r[:model], r[:crud] if models.index(r[:model]) end end |
#each_rpc(&block) ⇒ Object
53 54 55 |
# File 'lib/appbase/registry.rb', line 53 def each_rpc(&block) @rpc_methods.each(&block) end |
#register_crud(model, crud) ⇒ Object
47 48 49 50 51 |
# File 'lib/appbase/registry.rb', line 47 def register_crud(model, crud) if .find{ |r| r[:model] == model && r[:crud] == crud }.nil? << { model: model, crud: crud } end end |
#register_rpc(model, method_name, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/appbase/registry.rb', line 37 def register_rpc(model, method_name, ={}) rpc_registry_item = { model: (model.instance_of?(String) || model.instance_of?(Symbol)) ? Object.const_get(model.to_sym) : model, method: method_name.to_sym, auth: .has_key?(:auth) ? [:auth] : true } raise "#{model}.#{method_name} has already been registered" if contains_rpc_registry(rpc_registry_item) @rpc_methods << rpc_registry_item end |