class AppBase::Registry::RegistryTable

Public Class Methods

new() click to toggle source
# File lib/appbase/registry.rb, line 28
def initialize
  @rpc_methods = []
  @crud_permissions = []
end

Public Instance Methods

contains_rpc_registry(item) click to toggle source
# 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) click to toggle source
# 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 }
  @crud_permissions.each do |r|
    block.call r[:model], r[:crud] if models.index(r[:model])
  end
end
each_rpc(&block) click to toggle source
# File lib/appbase/registry.rb, line 53
def each_rpc(&block)
  @rpc_methods.each(&block)
end
register_crud(model, crud) click to toggle source
# File lib/appbase/registry.rb, line 47
def register_crud(model, crud)
  if @crud_permissions.find{ |r| r[:model] == model && r[:crud] == crud }.nil?
    @crud_permissions << { model: model, crud: crud }
  end
end
register_rpc(model, method_name, options={}) click to toggle source
# File lib/appbase/registry.rb, line 37
def register_rpc(model, method_name, options={})
  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: options.has_key?(:auth) ? options[:auth] : true
  }
  raise "#{model}.#{method_name} has already been registered" if contains_rpc_registry(rpc_registry_item)
  @rpc_methods << rpc_registry_item
end