Module: SmarterListing::Helper
- Defined in:
- lib/smarter_listing/helper.rb
Instance Method Summary collapse
- #_resource_params ⇒ Object
- #action_copy(object, path) ⇒ Object
- #action_destroy(object, path) ⇒ Object
- #action_edit(object, path) ⇒ Object
- #collection_ivar ⇒ Object
- #collection_sym ⇒ Object
- #current_engine ⇒ Object
- #model ⇒ Object
- #resource_ivar ⇒ Object
- #resource_sym ⇒ Object
- #resource_view_path ⇒ Object
- #table_name ⇒ Object
Instance Method Details
#_resource_params ⇒ Object
26 27 28 29 30 |
# File 'lib/smarter_listing/helper.rb', line 26 def _resource_params method = "#{resource_sym}_params".to_sym return send method if respond_to? method resource_params end |
#action_copy(object, path) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/smarter_listing/helper.rb', line 81 def action_copy(object, path) { name: :copy, custom_url: path, custom_icon: SmartListing.config.classes(:icon_copy), custom_title: 'Copy' } end |
#action_destroy(object, path) ⇒ Object
94 95 96 |
# File 'lib/smarter_listing/helper.rb', line 94 def action_destroy(object, path) {name: :destroy, url: path} end |
#action_edit(object, path) ⇒ Object
90 91 92 |
# File 'lib/smarter_listing/helper.rb', line 90 def action_edit(object, path) {name: :edit, url: path} end |
#collection_ivar ⇒ Object
8 9 10 |
# File 'lib/smarter_listing/helper.rb', line 8 def collection_ivar "@#{collection_sym}" end |
#collection_sym ⇒ Object
4 5 6 |
# File 'lib/smarter_listing/helper.rb', line 4 def collection_sym @collection_sym ||= model.to_s.underscore.sub('/','_').pluralize.to_sym end |
#current_engine ⇒ Object
36 37 38 39 |
# File 'lib/smarter_listing/helper.rb', line 36 def current_engine object = instance_variables.include?(:@_controller) ? @_controller : self object.class.module_parent == Object ? '' : object.class.module_parent.to_s.underscore end |
#model ⇒ 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 71 72 73 74 75 76 77 78 79 |
# File 'lib/smarter_listing/helper.rb', line 41 def model controller = instance_variables.include?(:@_controller) ? @_controller : self @model ||= begin # First priority is the namespaced model, e.g. User::Group resource_class ||= begin namespaced_class = controller.class.name.sub(/Controller/, '').singularize namespaced_class.constantize rescue NameError nil end # Second priority is the top namespace model, e.g. EngineName::Article for EngineName::Admin::ArticlesController resource_class ||= begin namespaced_classes = controller.class.name.sub(/Controller/, '').split('::') namespaced_class = [namespaced_classes.first, namespaced_classes.last].join('::').singularize namespaced_class.constantize rescue NameError nil end # Third priority the camelcased c, i.e. UserGroup resource_class ||= begin camelcased_class = controller.class.name.sub(/Controller/, '').gsub('::', '').singularize camelcased_class.constantize rescue NameError nil end # Otherwise use the Group class, or fail resource_class ||= begin class_name = controller.controller_name.classify class_name.constantize rescue NameError => e raise unless e..include?(class_name) nil end resource_class end end |
#resource_ivar ⇒ Object
22 23 24 |
# File 'lib/smarter_listing/helper.rb', line 22 def resource_ivar "@#{resource_sym}" end |
#resource_sym ⇒ Object
12 13 14 |
# File 'lib/smarter_listing/helper.rb', line 12 def resource_sym @resource_sym ||= model.to_s.underscore.sub('/','_').to_sym end |
#resource_view_path ⇒ Object
16 17 18 19 20 |
# File 'lib/smarter_listing/helper.rb', line 16 def resource_view_path path = model.name.tableize path = "#{current_engine}/#{path}" unless path.start_with?("#{current_engine}/") path end |
#table_name ⇒ Object
32 33 34 |
# File 'lib/smarter_listing/helper.rb', line 32 def table_name model.name.demodulize.tableize.to_sym end |