Class: AppBase::ModelConcern::ModelConcernHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/appbase/model_concern.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](model) ⇒ Object



117
118
119
120
# File 'lib/appbase/model_concern.rb', line 117

def [](model)
  raise "Invalid model" if model.class != Class
  helpers[model] ||= ModelConcernHelper.new(model)
end

Instance Method Details

#crud_allow(crud, criteria = :mine, &block) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/appbase/model_concern.rb', line 80

def crud_allow(crud, criteria=:mine, &block)
  validate_crud crud
  
  if criteria == :mine
    allow_mine crud
  else
    key = crud == :query ? :within : :if
    if criteria.instance_of? Hash
      allow_criteria_with_method_alias(crud, criteria[key])
    else
      show_usage(crud) if criteria != key || !block_given?
      allow_criteria_with_block(crud, block)
    end
  end
  AppBase::Registry.register_crud @model, crud
end

#symbol_array_manipulate(op, source, options) ⇒ Object

Raises:



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/appbase/model_concern.rb', line 97

def symbol_array_manipulate(op, source, options)
  raise InvalidUsage if op != :only && op != :except
  if options.has_key? op
    operands = options[op]
    operands = [operands] if operands.instance_of?(String) || operands.instance_of?(Symbol)
    raise InvalidUsage unless operands.instance_of?(Array)
    operands = operands.map {|c|c.to_sym}
    source.send({ only: '&', except: "-" }[op], operands)
  else
    source
  end
end