Class: AdminIt::Filter
- Extended by:
- DataBehavior, DisplayableName, ExtendIt::Base, ExtendIt::Dsl
- Includes:
- ExtendIt::Callbacks
- Defined in:
- lib/admin_it/filters/filter.rb
Direct Known Subclasses
Constant Summary collapse
- REGEXP =
/ (?<=\A|[,;|])\s* (?<full> (?<action>[!+\-])? (?<name>[a-zA-Z_][a-zA-Z0-9_]*) (?:\((?<params>[^)]*)\))? ) \s*(?=[,;|]|\z) /x
- ARGUMENT_REGEXP =
/ (?<=\A|[,;|])\s* (?: (?:(?<action>[+\-])|(?:(?<option>[a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*))? (?<token> (?:'(?:[^\\']|\\.)*')| (?:"(?:[^\\"]|\\.)*")| (?:[^,;|\s]+) ) ) \s*(?=[,;|]|\z) /x
Class Attribute Summary collapse
-
.filter_name ⇒ Object
readonly
Returns the value of attribute filter_name.
-
.resource ⇒ Object
readonly
Returns the value of attribute resource.
Class Method Summary collapse
- .apply(str, filters, filter_classes) ⇒ Object
- .attr_checker(*names) ⇒ Object extended from ExtendIt::Base
- .call_inherited(method_name, *args, base_first: false, &block) ⇒ Object extended from ExtendIt::Base
- .class_attr_reader(*attrs) ⇒ Object extended from ExtendIt::Base
- .create(name, _resource) ⇒ Object
- .display_name ⇒ Object extended from DisplayableName
- .display_name=(value) ⇒ Object extended from DisplayableName
- .dsl_eval(&block) ⇒ Object extended from ExtendIt::Dsl
- .inherited_class_reader(*names) ⇒ Object extended from ExtendIt::Base
- .load(str, filter_classes) ⇒ Object
- .metaclass(&block) ⇒ Object extended from ExtendIt::Base
Instance Method Summary collapse
- #apply(collection) ⇒ Object
- #dump ⇒ Object
-
#initialize ⇒ Filter
constructor
A new instance of Filter.
- #load(str) ⇒ Object
- #name ⇒ Object
- #run_callbacks(*names, arguments: [], original_context: false) ⇒ Object included from ExtendIt::Callbacks
Constructor Details
#initialize ⇒ Filter
Returns a new instance of Filter.
96 97 98 |
# File 'lib/admin_it/filters/filter.rb', line 96 def initialize run_callbacks :initialize end |
Class Attribute Details
.filter_name ⇒ Object (readonly)
Returns the value of attribute filter_name.
41 42 43 |
# File 'lib/admin_it/filters/filter.rb', line 41 def filter_name @filter_name end |
.resource ⇒ Object (readonly)
Returns the value of attribute resource.
41 42 43 |
# File 'lib/admin_it/filters/filter.rb', line 41 def resource @resource end |
Class Method Details
.apply(str, filters, filter_classes) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/admin_it/filters/filter.rb', line 79 def self.apply(str, filters, filter_classes) list = str.scan(Filter::REGEXP) filters.clear if list.all? { |_, act, _, _| act.nil? || act.empty? } list.each do |full, action, name, params| name = name.to_sym if action == '-' filters.delete(name) elsif action == '!' filters[name].load(params) if filters.key?(name) else filters[name] = Filter.load(full, filter_classes) end end end |
.attr_checker(*names) ⇒ Object Originally defined in module ExtendIt::Base
.call_inherited(method_name, *args, base_first: false, &block) ⇒ Object Originally defined in module ExtendIt::Base
.class_attr_reader(*attrs) ⇒ Object Originally defined in module ExtendIt::Base
.create(name, _resource) ⇒ Object
64 65 66 |
# File 'lib/admin_it/filters/filter.rb', line 64 def self.create(name, _resource) create_class(name, _resource) end |
.display_name ⇒ Object Originally defined in module DisplayableName
.display_name=(value) ⇒ Object Originally defined in module DisplayableName
.dsl_eval(&block) ⇒ Object Originally defined in module ExtendIt::Dsl
.inherited_class_reader(*names) ⇒ Object Originally defined in module ExtendIt::Base
.load(str, filter_classes) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/admin_it/filters/filter.rb', line 68 def self.load(str, filter_classes) m = REGEXP.match(str) return nil if m.nil? || m[:action] == '-' name = m[:name].to_sym filter_class = filter_classes.find { |f| f.filter_name == name } return nil if filter_class.nil? filter = filter_class.new filter.load(m[:params]) filter end |
.metaclass(&block) ⇒ Object Originally defined in module ExtendIt::Base
Instance Method Details
#apply(collection) ⇒ Object
127 128 129 |
# File 'lib/admin_it/filters/filter.rb', line 127 def apply(collection) collection end |
#dump ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/admin_it/filters/filter.rb', line 104 def dump args = [] opts = {} result = '' run_callbacks :save, arguments: { arguments: args, options: opts } do result = "#{name}" unless args.empty? && opts.empty? args.concat(opts.map { |k, v| "#{k}:#{v}" }) result << "(#{args.join(',')})" end end result end |
#load(str) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/admin_it/filters/filter.rb', line 118 def load(str) return if str.nil? args = parse_arguments(str) unless args.empty? opts = args. run_callbacks :load, arguments: { arguments: args, options: opts } end end |
#name ⇒ Object
100 101 102 |
# File 'lib/admin_it/filters/filter.rb', line 100 def name @name ||= self.class.filter_name end |