Module: Effective::Resources::Paths
- Included in:
- Effective::Resource
- Defined in:
- app/models/effective/resources/paths.rb
Instance Method Summary collapse
- #action_path(action, check: false) ⇒ Object
- #action_path_helper(action, at: true) ⇒ Object
- #controller_file ⇒ Object
- #datatable_file ⇒ Object
- #destroy_path(check: false) ⇒ Object
- #edit_path(check: false) ⇒ Object
- #edit_path_helper(at: true) ⇒ Object
-
#index_path(check: false) ⇒ Object
(also: #index_path_helper)
Controller REST helper paths.
-
#model_file ⇒ Object
Default file paths.
- #new_path(check: false) ⇒ Object (also: #new_path_helper)
- #path_exists?(path, param = nil, verb = :get) ⇒ Boolean
- #show_path(check: false) ⇒ Object
- #show_path_helper(at: true) ⇒ Object
- #view_file(action = :index, partial: false) ⇒ Object
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)) end |
#action_path_helper(action, at: true) ⇒ Object
55 56 57 |
# File 'app/models/effective/resources/paths.rb', line 55 def action_path_helper(action, at: true) action_path(action) + '(' + (at ? '@' : '') + name + ')' end |
#controller_file ⇒ Object
64 65 66 |
# File 'app/models/effective/resources/paths.rb', line 64 def controller_file File.join('app/controllers', namespace.to_s, "#{plural_name}_controller.rb") end |
#datatable_file ⇒ Object
68 69 70 |
# File 'app/models/effective/resources/paths.rb', line 68 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
51 52 53 |
# File 'app/models/effective/resources/paths.rb', line 51 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_file ⇒ Object
Default file paths
60 61 62 |
# File 'app/models/effective/resources/paths.rb', line 60 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
36 37 38 39 40 41 |
# File 'app/models/effective/resources/paths.rb', line 36 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
47 48 49 |
# File 'app/models/effective/resources/paths.rb', line 47 def show_path_helper(at: true) show_path + '(' + (at ? '@' : '') + name + ')' end |
#view_file(action = :index, partial: false) ⇒ Object
72 73 74 |
# File 'app/models/effective/resources/paths.rb', line 72 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 |