Module: Arcane::Parameters

Extended by:
ActiveSupport::Concern
Defined in:
lib/arcane/parameters.rb

Instance Method Summary collapse

Instance Method Details

#as(user) ⇒ Object



29
30
31
32
33
# File 'lib/arcane/parameters.rb', line 29

def as(user)
  params = self.dup
  params.user = user
  return params
end

#for(object) ⇒ Object



23
24
25
26
27
# File 'lib/arcane/parameters.rb', line 23

def for(object)
  params = self.dup
  params.object = object
  return params
end

#on(action) ⇒ Object



35
36
37
38
39
# File 'lib/arcane/parameters.rb', line 35

def on(action)
  params = self.dup
  params.action = action
  return params
end

#refine(opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/arcane/parameters.rb', line 41

def refine(opts={})
  params = self.dup

  params.action = opts[:action] || action || params[:action]
  params.user   = opts[:user]   || user
  params.object = opts[:object] || object

  refinery = Arcane::Finder.new(params.object).refinery.new(params.object, params.user)

  args = if params.action.nil?
    []
  elsif refinery.respond_to?(params.action)
    refinery.public_send(params.action)
  elsif refinery.respond_to?(:default)
    refinery.default
  else
    []
  end

  root = if refinery.respond_to?(:root)
    refinery.root
  elsif refinery.class.respond_to?(:root)
    refinery.class.root
  else
    Arcane::Finder.object_name(params.object)
  end

  return root.present? ? params.require(root.underscore).permit(*args) : params.permit(*args)

end