Module: Casino::Collection

Defined in:
lib/casino/collection.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#answer(method_name) ⇒ Object (readonly)

Returns the value of attribute answer.



3
4
5
# File 'lib/casino/collection.rb', line 3

def answer
  @answer
end

#intersectionObject (readonly)

Returns the value of attribute intersection.



3
4
5
# File 'lib/casino/collection.rb', line 3

def intersection
  @intersection
end

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/casino/collection.rb', line 5

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#dimensionsObject



34
35
36
# File 'lib/casino/collection.rb', line 34

def dimensions
  registry[:dimension]
end

#documentObject



50
51
52
# File 'lib/casino/collection.rb', line 50

def document
  @document ||= Casino::Document.new(key, questions.map(&:name)).compose
end

#focusObject



42
43
44
# File 'lib/casino/collection.rb', line 42

def focus
  registry[:focus]
end

#insert(*documents) ⇒ Object



84
85
86
87
88
89
# File 'lib/casino/collection.rb', line 84

def insert(*documents)
  matching_intersections = match_intersections documents
  matching_results = determine_results matching_intersections
  merge matching_results
  stored_results.where(id: matching_results.map(&:id))
end

#keyObject



54
55
56
# File 'lib/casino/collection.rb', line 54

def key
  Digest::SHA1.hexdigest(key_base)
end

#projectionObject



58
59
60
# File 'lib/casino/collection.rb', line 58

def projection
  Casino::Projection.new(focus_model).where(intersection.selector)
end

#query(label, *criteria) ⇒ Object



66
67
68
# File 'lib/casino/collection.rb', line 66

def query(label, *criteria)
  Query.new(label, [], *criteria)
end

#questionsObject



38
39
40
# File 'lib/casino/collection.rb', line 38

def questions
  registry[:question]
end

#resultsObject



70
71
72
73
# File 'lib/casino/collection.rb', line 70

def results
  persist_results if pending_results.any?
  stored_results
end

#storeObject



46
47
48
# File 'lib/casino/collection.rb', line 46

def store
  @store ||= Store.new document
end

#updateObject



75
76
77
78
# File 'lib/casino/collection.rb', line 75

def update
  merge all_results
  stored_results
end