Class: AdminIt::Filter

Inherits:
Object
  • Object
show all
Extended by:
DataBehavior, ExtendIt::Asserts, ExtendIt::Class, ExtendIt::Dsl
Includes:
ExtendIt::Callbacks
Defined in:
lib/admin_it/filters/filter.rb

Direct Known Subclasses

EntityFilter, FieldFilter

Constant Summary collapse

REGEXP =
/\A(?<name>[a-zA-Z_][a-zA-Z0-9_]*)(?:\((?<params>[^)]*)\))?\z/

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.filter_nameObject (readonly)

Returns the value of attribute filter_name.



25
26
27
# File 'lib/admin_it/filters/filter.rb', line 25

def filter_name
  @filter_name
end

.resourceObject (readonly)

Returns the value of attribute resource.



25
26
27
# File 'lib/admin_it/filters/filter.rb', line 25

def resource
  @resource
end

Class Method Details

.call_inherited(method_name, *args, base_first: false, &block) ⇒ Object Originally defined in module ExtendIt::Class

.class_attr_reader(*attrs) ⇒ Object Originally defined in module ExtendIt::Class

.create(name, _resource) ⇒ Object



48
49
50
# File 'lib/admin_it/filters/filter.rb', line 48

def self.create(name, _resource)
  create_class(name, _resource)
end

.dsl_accessor(*names, default: nil, &setter) ⇒ Object Originally defined in module ExtendIt::Dsl

.dsl_block(*names) ⇒ Object Originally defined in module ExtendIt::Dsl

.dsl_boolean(*names, default: true) ⇒ Object Originally defined in module ExtendIt::Dsl

.dsl_use_hash(hash_name) ⇒ Object Originally defined in module ExtendIt::Dsl

.inherited_class_reader(*names) ⇒ Object Originally defined in module ExtendIt::Class

.load(str, filters) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/admin_it/filters/filter.rb', line 52

def self.load(str, filters)
  m = REGEXP.match(str)
  return nil if m.nil?
  name = m[:name].to_sym
  filter_class = filters.find { |f| f.filter_name == name }
  return nil if filter_class.nil?
  opts = {}
  args = m[:params].nil? ? [] : m[:params].split(',').map do |param|
    param.strip!
    arr = param.split(':')
    if arr.size > 1
      opts[arr[0].strip.to_sym] = arr[1].strip
      nil
    else
      arr[0]
    end
  end
  args << opts unless opts.empty?
  filter_class.new(*args.compact)
end

Instance Method Details

#apply(collection) ⇒ Object



96
97
98
# File 'lib/admin_it/filters/filter.rb', line 96

def apply(collection)
  collection
end

#change(str) ⇒ Object



93
94
# File 'lib/admin_it/filters/filter.rb', line 93

def change(str)
end

#dumpObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/admin_it/filters/filter.rb', line 79

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

#nameObject



75
76
77
# File 'lib/admin_it/filters/filter.rb', line 75

def name
  @name ||= self.class.filter_name
end

#run_callbacks(*names, arguments: [], original_context: false) ⇒ Object Originally defined in module ExtendIt::Callbacks