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
332 333 334 335 |
# File 'lib/yummy_guide/administrate/filters.rb', line 332 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
353 354 355 356 |
# File 'lib/yummy_guide/administrate/filters.rb', line 353 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
337 338 339 340 341 |
# File 'lib/yummy_guide/administrate/filters.rb', line 337 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
343 344 345 346 347 348 349 350 351 |
# File 'lib/yummy_guide/administrate/filters.rb', line 343 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 |