Module: HasCrudFor

Defined in:
lib/has_crud_for.rb,
lib/has_crud_for/version.rb

Constant Summary collapse

DEFAULT_METHODS =
[:find, :build, :create, :update, :destroy]
VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#has_crud_for(models, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/has_crud_for.rb', line 8

def has_crud_for(models, options = {})
  methods = begin
    if only = options[:only]
      only
    elsif except = options[:except]
      DEFAULT_METHODS - except
    else
      DEFAULT_METHODS
    end
  end

  name = (options[:as] || models).to_s.singularize
  if through = options[:through]
    parent = through.to_s.singularize
    define_crud_through_methods(models, name, parent, methods)
  else
    define_crud_methods(models, name, methods)
  end
end