Module: Ransack::Adapters::ActiveRecord::Base
- Defined in:
- lib/ransack/adapters/active_record/base.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#authorizable_ransackable_associations ⇒ Object
Bare list of all potentially searchable associations.
-
#authorizable_ransackable_attributes ⇒ Object
Bare list of all potentially searchable attributes.
- #ransack(params = {}, options = {}) ⇒ Object
- #ransack!(params = {}, options = {}) ⇒ Object
- #ransack_alias(new_name, old_name) ⇒ Object
-
#ransackable_associations(auth_object = nil) ⇒ Object
Ransackable_associations, by default, returns the names of all associations as an array of strings.
-
#ransackable_attributes(auth_object = nil) ⇒ Object
Ransackable_attributes, by default, returns all column names and any defined ransackers as an array of strings.
-
#ransackable_scopes(auth_object = nil) ⇒ Object
Ransackable_scopes, by default, returns an empty array i.e.
-
#ransackable_scopes_skip_sanitize_args ⇒ Object
ransack_scope_skip_sanitize_args, by default, returns an empty array.
- #ransacker(name, opts = {}, &block) ⇒ Object
-
#ransortable_attributes(auth_object = nil) ⇒ Object
Ransortable_attributes, by default, returns the names of all attributes available for sorting as an array of strings.
Class Method Details
.extended(base) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/ransack/adapters/active_record/base.rb', line 6 def self.extended(base) base.class_eval do class_attribute :_ransackers class_attribute :_ransack_aliases self._ransackers ||= {} self._ransack_aliases ||= {} end end |
Instance Method Details
#authorizable_ransackable_associations ⇒ Object
Bare list of all potentially searchable associations. Searchable associations need to be explicitly allowlisted through the ‘ransackable_associations` method in each model, but if you’re allowing almost everything to be searched, this list can be used as a base for exclusions.
93 94 95 |
# File 'lib/ransack/adapters/active_record/base.rb', line 93 def reflect_on_all_associations.map { |a| a.name.to_s } end |
#authorizable_ransackable_attributes ⇒ Object
Bare list of all potentially searchable attributes. Searchable attributes need to be explicitly allowlisted through the ‘ransackable_attributes` method in each model, but if you’re allowing almost everything to be searched, this list can be used as a base for exclusions.
78 79 80 81 82 83 84 85 |
# File 'lib/ransack/adapters/active_record/base.rb', line 78 def if Ransack::SUPPORTS_ATTRIBUTE_ALIAS column_names + _ransackers.keys + _ransack_aliases.keys + attribute_aliases.keys else column_names + _ransackers.keys + _ransack_aliases.keys end.uniq end |
#ransack(params = {}, options = {}) ⇒ Object
15 16 17 |
# File 'lib/ransack/adapters/active_record/base.rb', line 15 def ransack(params = {}, = {}) Search.new(self, params, ) end |
#ransack!(params = {}, options = {}) ⇒ Object
19 20 21 |
# File 'lib/ransack/adapters/active_record/base.rb', line 19 def ransack!(params = {}, = {}) ransack(params, .merge(ignore_unknown_conditions: false)) end |
#ransack_alias(new_name, old_name) ⇒ Object
28 29 30 31 |
# File 'lib/ransack/adapters/active_record/base.rb', line 28 def ransack_alias(new_name, old_name) self._ransack_aliases = _ransack_aliases.merge new_name.to_s => old_name.to_s end |
#ransackable_associations(auth_object = nil) ⇒ Object
Ransackable_associations, by default, returns the names of all associations as an array of strings. For overriding with a whitelist array of strings.
45 46 47 |
# File 'lib/ransack/adapters/active_record/base.rb', line 45 def ransackable_associations(auth_object = nil) @ransackable_associations ||= deprecated_ransackable_list(:ransackable_associations) end |
#ransackable_attributes(auth_object = nil) ⇒ Object
Ransackable_attributes, by default, returns all column names and any defined ransackers as an array of strings. For overriding with a whitelist array of strings.
37 38 39 |
# File 'lib/ransack/adapters/active_record/base.rb', line 37 def ransackable_attributes(auth_object = nil) @ransackable_attributes ||= deprecated_ransackable_list(:ransackable_attributes) end |
#ransackable_scopes(auth_object = nil) ⇒ Object
Ransackable_scopes, by default, returns an empty array i.e. no class methods/scopes are authorized. For overriding with a whitelist array of symbols.
61 62 63 |
# File 'lib/ransack/adapters/active_record/base.rb', line 61 def ransackable_scopes(auth_object = nil) [] end |
#ransackable_scopes_skip_sanitize_args ⇒ Object
ransack_scope_skip_sanitize_args, by default, returns an empty array. i.e. use the sanitize_scope_args setting to determine if args should be converted. For overriding with a list of scopes which should be passed the args as-is.
69 70 71 |
# File 'lib/ransack/adapters/active_record/base.rb', line 69 def ransackable_scopes_skip_sanitize_args [] end |
#ransacker(name, opts = {}, &block) ⇒ Object
23 24 25 26 |
# File 'lib/ransack/adapters/active_record/base.rb', line 23 def ransacker(name, opts = {}, &block) self._ransackers = _ransackers.merge name.to_s => Ransacker .new(self, name, opts, &block) end |
#ransortable_attributes(auth_object = nil) ⇒ Object
Ransortable_attributes, by default, returns the names of all attributes available for sorting as an array of strings. For overriding with a whitelist array of strings.
53 54 55 |
# File 'lib/ransack/adapters/active_record/base.rb', line 53 def ransortable_attributes(auth_object = nil) ransackable_attributes(auth_object) end |