Method: Hyperactive::Index::Indexable::ClassMethods#select
- Defined in:
- lib/hyperactive/index.rb
#select(name, &block) ⇒ Object
Will define a method called name that will include all existing instances of this class that when yielded to the block returns true. Will only return instances saved after this selector is defined.
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/hyperactive/index.rb', line 178 def select(name, &block) #:yields: instance key = collection_key(name) Archipelago::Pirate::BLACKBEARD[key] ||= Hyperactive::Hash::Head.get_instance self.class.class_eval do define_method(name) do Archipelago::Pirate::BLACKBEARD[key] end end self.save_hooks << MatchSaver.new(key, block, :select) self.destroy_hooks << MatchSaver.new(key, block, :delete_if_match) end |