Class: Carnival::Action

Inherits:
Object
  • Object
show all
Defined in:
app/models/carnival/action.rb

Direct Known Subclasses

BatchAction

Constant Summary collapse

PARTIAL_DEFAULT =
:default
PARTIAL_DELETE =
:delete
PARTIAL_REMOTE =
:remote

Instance Method Summary collapse

Constructor Details

#initialize(name, params = {}) ⇒ Action

Returns a new instance of Action.



8
9
10
11
12
13
14
15
# File 'app/models/carnival/action.rb', line 8

def initialize(name, params={})
  @name = name
  @params = params
  @partial = default_partial
  @path = params[:path] if params[:path].present?
  @controller = params[:controller]
  @route_name = params[:route_name]
end

Instance Method Details

#default_partialObject



61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/carnival/action.rb', line 61

def default_partial()
  if [:new, :edit, :show].include?(@name)
    PARTIAL_DEFAULT
  elsif @name == :destroy
    PARTIAL_DELETE
  elsif remote?
    PARTIAL_REMOTE
  else
    PARTIAL_DEFAULT
  end
end

#nameObject



48
49
50
# File 'app/models/carnival/action.rb', line 48

def name
  @name
end

#paramsObject



44
45
46
# File 'app/models/carnival/action.rb', line 44

def params
  @params
end

#partialObject



40
41
42
# File 'app/models/carnival/action.rb', line 40

def partial
  @partial
end

#path(presenter, extra_params = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/carnival/action.rb', line 17

def path(presenter, extra_params={})
  if @path.nil?
    params = {controller: @controller || presenter.controller_name, action: @name}
  elsif !@path[:controller].nil?
    params = @path
  else
    params = {path: @path}
  end
  params = params.merge(extra_params) if extra_params.present?
  params = params.merge(:only_path => true)
  if @route_name
    Rails.application.routes.url_helpers.send(@route_name, params)
  else
    url_for(params)
  end
end

#remote?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/carnival/action.rb', line 52

def remote?
  @params[:remote]
end

#show(record) ⇒ Object



34
35
36
37
38
# File 'app/models/carnival/action.rb', line 34

def show(record)
  return true if !params[:show_func]
  return true if !record.respond_to? params[:show_func]
  record.send params[:show_func]
end

#targetObject



56
57
58
59
# File 'app/models/carnival/action.rb', line 56

def target
  return :record if @params[:target].nil?
  @params[:target]
end