Module: Flock::MockService
Constant Summary collapse
- EXEC_OPS =
{ Edges::ExecuteOperationType::Add => :add, Edges::ExecuteOperationType::Remove => :remove, Edges::ExecuteOperationType::Archive => :archive, Edges::ExecuteOperationType::Negate => :negate }
Instance Attribute Summary collapse
-
#fixtures ⇒ Object
Returns the value of attribute fixtures.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #clear ⇒ Object
- #contains(source, graph, dest) ⇒ Object
- #count(select_operations) ⇒ Object
- #execute(operations) ⇒ Object
- #inspect ⇒ Object
- #load(fixtures = nil) ⇒ Object
- #select(select_operations, page) ⇒ Object
Instance Attribute Details
#fixtures ⇒ Object
Returns the value of attribute fixtures.
12 13 14 |
# File 'lib/flock/mock_service.rb', line 12 def fixtures @fixtures end |
#timeout ⇒ Object
Returns the value of attribute timeout.
12 13 14 |
# File 'lib/flock/mock_service.rb', line 12 def timeout @timeout end |
Instance Method Details
#clear ⇒ Object
14 15 16 17 |
# File 'lib/flock/mock_service.rb', line 14 def clear @forward_edges = nil @backward_edges = nil end |
#contains(source, graph, dest) ⇒ Object
54 55 56 |
# File 'lib/flock/mock_service.rb', line 54 def contains(source, graph, dest) forward_edges[graph][Edges::EdgeState::Positive][source].include?(dest) end |
#count(select_operations) ⇒ Object
58 59 60 |
# File 'lib/flock/mock_service.rb', line 58 def count(select_operations) select_query(select_operations).size end |
#execute(operations) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/flock/mock_service.rb', line 37 def execute(operations) operations = operations.operations operations.each do |operation| term = operation.term graph, source = term.graph_id, term.source_id dest = term.destination_ids && term.destination_ids.unpack('Q*') source, dest = dest, source unless term.is_forward self.send(EXEC_OPS[operation.operation_type], source, graph, dest) end end |
#inspect ⇒ Object
33 34 35 |
# File 'lib/flock/mock_service.rb', line 33 def inspect "Flock::MockService: ( #{@forward_edges.inspect} - #{@backward_edges.inspect} )" end |
#load(fixtures = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/flock/mock_service.rb', line 19 def load(fixtures = nil) fixtures ||= self.fixtures or raise "No flock fixtures specified. either pass fixtures to load, or set Flock::MockService.fixtures." clear fixtures.each do |fixture| file, graph, source, dest = fixture.values_at(:file, :graph, :source, :destination) YAML::load(ERB.new(File.open(file, 'r').read).result(binding)).sort.each do |key, row| add(row[source], graph, row[dest]) end end end |
#select(select_operations, page) ⇒ Object
50 51 52 |
# File 'lib/flock/mock_service.rb', line 50 def select(select_operations, page) iterate(select_query(select_operations), page) end |