Module: Ohm::Sorted::ClassMethods
- Defined in:
- lib/ohm/sorted.rb
Instance Method Summary collapse
- #sorted(attribute, options = {}) ⇒ Object
- #sorted_find(attribute, dict = {}) ⇒ Object
- #sorted_index_exists?(attribute, options = nil) ⇒ Boolean
- #sorted_index_key(attribute, dict = {}) ⇒ Object
- #sorted_indices ⇒ Object
Instance Method Details
#sorted(attribute, options = {}) ⇒ Object
153 154 155 |
# File 'lib/ohm/sorted.rb', line 153 def sorted(attribute, ={}) sorted_indices << [attribute, ] end |
#sorted_find(attribute, dict = {}) ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'lib/ohm/sorted.rb', line 161 def sorted_find(attribute, dict={}) unless sorted_index_exists?(attribute, (dict)) raise index_not_found(attribute) end index_key = sorted_index_key(attribute, dict) Ohm::SortedSet.new(index_key, key, self) end |
#sorted_index_exists?(attribute, options = nil) ⇒ Boolean
170 171 172 |
# File 'lib/ohm/sorted.rb', line 170 def sorted_index_exists?(attribute, =nil) !!sorted_indices.detect { |i| i == [attribute, ] } end |
#sorted_index_key(attribute, dict = {}) ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/ohm/sorted.rb', line 174 def sorted_index_key(attribute, dict={}) index_key = [key, "sorted", attribute] if dict.size == 1 index_key.concat(dict.first) elsif dict.keys.size > 1 raise ArgumentError end index_key.join(":") end |
#sorted_indices ⇒ Object
157 158 159 |
# File 'lib/ohm/sorted.rb', line 157 def sorted_indices @sorted_indices ||= [] end |