Module: Effective::Resources::Paths

Included in:
Effective::Resource
Defined in:
app/models/effective/resources/paths.rb

Instance Method Summary collapse

Instance Method Details

#action_path(action, check: false) ⇒ Object



31
32
33
34
# File 'app/models/effective/resources/paths.rb', line 31

def action_path(action, check: false)
  path = [action, namespace, name, 'path'].compact * '_'
  path if (!check || path_exists?(path, 1, :any))
end

#action_path_helper(action, at: true) ⇒ Object



60
61
62
# File 'app/models/effective/resources/paths.rb', line 60

def action_path_helper(action, at: true)
  action_path(action) + '(' + (at ? '@' : '') + name + ')'
end

#action_post_path(action, check: false) ⇒ Object



36
37
38
39
# File 'app/models/effective/resources/paths.rb', line 36

def action_post_path(action, check: false)
  path = [action, namespace, name, 'path'].compact * '_'
  path if (!check || path_exists?(path, 1, :post) || path_exists?(path, 1, :put) || path_exists?(path, 1, :patch))
end

#controller_fileObject



69
70
71
# File 'app/models/effective/resources/paths.rb', line 69

def controller_file
  File.join('app/controllers', namespace.to_s, "#{plural_name}_controller.rb")
end

#datatable_fileObject



73
74
75
# File 'app/models/effective/resources/paths.rb', line 73

def datatable_file
  File.join('app/datatables', namespace.to_s, "#{plural_name}_datatable.rb")
end

#destroy_path(check: false) ⇒ Object



21
22
23
24
# File 'app/models/effective/resources/paths.rb', line 21

def destroy_path(check: false)
  path = [namespace, name, 'path'].compact * '_'
  path if (!check || path_exists?(path, 1, :delete))
end

#edit_path(check: false) ⇒ Object



26
27
28
29
# File 'app/models/effective/resources/paths.rb', line 26

def edit_path(check: false)
  path = ['edit', namespace, name, 'path'].compact * '_'
  path if (!check || path_exists?(path, 1))
end

#edit_path_helper(at: true) ⇒ Object



56
57
58
# File 'app/models/effective/resources/paths.rb', line 56

def edit_path_helper(at: true)
  edit_path + '(' + (at ? '@' : '') + name + ')'
end

#index_path(check: false) ⇒ Object Also known as: index_path_helper

Controller REST helper paths



6
7
8
9
# File 'app/models/effective/resources/paths.rb', line 6

def index_path(check: false)
  path = [namespace, plural_name, 'path'].compact * '_'
  path if (!check || path_exists?(path))
end

#model_fileObject

Default file paths



65
66
67
# File 'app/models/effective/resources/paths.rb', line 65

def model_file
  File.join('app/models', class_path.to_s, "#{name}.rb")
end

#new_path(check: false) ⇒ Object Also known as: new_path_helper



11
12
13
14
# File 'app/models/effective/resources/paths.rb', line 11

def new_path(check: false)
  path = ['new', namespace, name, 'path'].compact * '_'
  path if (!check || path_exists?(path))
end

#path_exists?(path, param = nil, verb = :get) ⇒ Boolean



41
42
43
44
45
46
# File 'app/models/effective/resources/paths.rb', line 41

def path_exists?(path, param = nil, verb = :get)
  routes = Rails.application.routes

  return false unless routes.url_helpers.respond_to?(path)
  (routes.recognize_path(routes.url_helpers.send(path, param), method: verb).present? rescue false)
end

#show_path(check: false) ⇒ Object



16
17
18
19
# File 'app/models/effective/resources/paths.rb', line 16

def show_path(check: false)
  path = [namespace, name, 'path'].compact * '_'
  path if (!check || path_exists?(path, 1))
end

#show_path_helper(at: true) ⇒ Object



52
53
54
# File 'app/models/effective/resources/paths.rb', line 52

def show_path_helper(at: true)
  show_path + '(' + (at ? '@' : '') + name + ')'
end

#view_file(action = :index, partial: false) ⇒ Object



77
78
79
# File 'app/models/effective/resources/paths.rb', line 77

def view_file(action = :index, partial: false)
  File.join('app/views', namespace.to_s, (namespace.present? ? '' : class_path), plural_name, "#{'_' if partial}#{action}.html.haml")
end