Module: YummyGuide::Administrate::Filters::Resolver
- Defined in:
- lib/yummy_guide/administrate/filters.rb
Class Method Summary collapse
- .attributes_for(dashboard) ⇒ Object
- .constant_value(dashboard, name) ⇒ Object
- .normalize_attributes(attributes) ⇒ Object
- .normalize_field(name, field) ⇒ Object
Class Method Details
.attributes_for(dashboard) ⇒ Object
291 292 293 294 |
# File 'lib/yummy_guide/administrate/filters.rb', line 291 def attributes_for(dashboard) source = dashboard.respond_to?(:filter_attributes) ? dashboard.filter_attributes : constant_value(dashboard, :FILTER_ATTRIBUTES) normalize_attributes(source || {}) end |
.constant_value(dashboard, name) ⇒ Object
312 313 314 315 |
# File 'lib/yummy_guide/administrate/filters.rb', line 312 def constant_value(dashboard, name) target = dashboard.is_a?(Class) ? dashboard : dashboard.class target.const_get(name, false) if target.const_defined?(name, false) end |
.normalize_attributes(attributes) ⇒ Object
296 297 298 299 300 |
# File 'lib/yummy_guide/administrate/filters.rb', line 296 def normalize_attributes(attributes) attributes.to_h.map do |name, field| [name.to_sym, normalize_field(name, field)] end.to_h end |
.normalize_field(name, field) ⇒ Object
302 303 304 305 306 307 308 309 310 |
# File 'lib/yummy_guide/administrate/filters.rb', line 302 def normalize_field(name, field) if field.respond_to?(:with_name) field.with_name(name) elsif field.is_a?(Class) && field < Base field..with_name(name) else raise ArgumentError, "Unsupported filter field for #{name}: #{field.inspect}" end end |