Module: AeEasy::Core::Mock::FakeExecutor
- Includes:
- AnswersEngine::Plugin::ContextExposer
- Included in:
- FakeParser, FakeSeeder
- Defined in:
- lib/ae_easy/core/mock/fake_executor.rb
Overview
Fake executor that emulates `AnswersEngine` executor.
Instance Attribute Summary collapse
-
#content ⇒ String?
Page content.
-
#failed_content ⇒ String?
Failed page content.
Class Method Summary collapse
-
.check_compatibility(source, fragment) ⇒ Hash
Validate executor methods compatibility.
Instance Method Summary collapse
-
#clear_draft_outputs ⇒ Object
Remove all elements on outputs.
-
#clear_draft_pages ⇒ Object
Remove all elements on pages.
-
#db ⇒ Object
Fake database to represent what it is saved.
-
#execute_script(file_path, vars = {}) ⇒ Object
Execute an script file as an executor.
-
#find_output(collection = 'default', query = {}) ⇒ Hash?
Find one output by collection and query with pagination.
-
#find_outputs(collection = 'default', query = {}, page = 1, per_page = 30) ⇒ Array
Find outputs by collection and query with pagination.
-
#flush ⇒ Object
Save all drafts into db and clear draft queues.
-
#flush_outputs ⇒ Object
Save draft outputs into db and clear draft queue.
-
#flush_pages ⇒ Object
Save draft pages into db and clear draft queue.
-
#initialize(opts = {}) ⇒ Object
Initialize object.
-
#job_id ⇒ Integer?
Fake job ID used by executor.
-
#job_id=(value) ⇒ Object
Set fake job id value.
-
#outputs ⇒ Array
Draft outputs, usually get saved after execution.
-
#page ⇒ Hash?
Current page used by executor.
-
#page=(value) ⇒ Object
Set current page.
-
#pages ⇒ Array
Draft pages, usually get saved after execution.
-
#save_outputs(list) ⇒ Object
Save an output collection on db.
-
#save_pages(list) ⇒ Object
Save a page collection on db.
-
#saved_outputs ⇒ Object
Retrive a list of saved outputs.
-
#saved_pages ⇒ Object
Retrive a list of saved pages.
Instance Attribute Details
#content ⇒ String?
Page content.
8 9 10 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 8 def content @content end |
#failed_content ⇒ String?
Failed page content.
11 12 13 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 11 def failed_content @failed_content end |
Class Method Details
.check_compatibility(source, fragment) ⇒ Hash
Validate executor methods compatibility.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 23 def self.check_compatibility source, fragment report = AeEasy::Core.analyze_compatibility source, fragment unless report[:new].count < 1 # Warn when outdated warn <<-LONGDESC.gsub(/^\s+/,'') It seems answersengine has new unmapped methods, try updating ae_easy-core gem or contacting gem maintainer to update it. New methods: #{report[:new].join ', '} LONGDESC end # Ensure no missing methods unless report[:is_compatible] = <<-LONGDESC.gsub(/^\s+/,'') There are missing methods! Check your answersengine gem version. Missing methods: #{report[:missing].join ', '} LONGDESC raise AeEasy::Core::Exception::OutdatedError.new() end report end |
Instance Method Details
#clear_draft_outputs ⇒ Object
Remove all elements on outputs.
67 68 69 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 67 def clear_draft_outputs @outputs.clear end |
#clear_draft_pages ⇒ Object
Remove all elements on pages.
61 62 63 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 61 def clear_draft_pages @pages.clear end |
#db ⇒ Object
Fake database to represent what it is saved.
72 73 74 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 72 def db @db ||= AeEasy::Core::Mock::FakeDb.new end |
#execute_script(file_path, vars = {}) ⇒ Object
Execute an script file as an executor.
200 201 202 203 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 200 def execute_script file_path, vars = {} eval(File.read(file_path), isolated_binding(vars), file_path) flush end |
#find_output(collection = 'default', query = {}) ⇒ Hash?
Find one output by collection and query with pagination.
192 193 194 195 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 192 def find_output collection = 'default', query = {} result = find_outputs(collection, query, 1, 1) result.nil? ? nil : result.first end |
#find_outputs(collection = 'default', query = {}, page = 1, per_page = 30) ⇒ Array
Find outputs by collection and query with pagination.
177 178 179 180 181 182 183 184 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 177 def find_outputs collection = 'default', query = {}, page = 1, per_page = 30 count = 0 offset = (page - 1) * per_page fixed_query = query.merge( '_collection' => collection ) db.query :outputs, fixed_query, offset, per_page end |
#flush ⇒ Object
Save all drafts into db and clear draft queues.
164 165 166 167 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 164 def flush flush_pages flush_outputs end |
#flush_outputs ⇒ Object
Save draft outputs into db and clear draft queue.
158 159 160 161 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 158 def flush_outputs save_outputs outputs clear_draft_outputs end |
#flush_pages ⇒ Object
Save draft pages into db and clear draft queue.
152 153 154 155 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 152 def flush_pages save_pages pages clear_draft_pages end |
#initialize(opts = {}) ⇒ Object
Initialize object.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 85 def initialize opts = {} unless opts[:pages].nil? || opts[:pages].is_a?(Array) raise ArgumentError.new "Pages must be an array." end @pages = opts[:pages] unless opts[:outputs].nil? || opts[:outputs].is_a?(Array) raise ArgumentError.new "Outputs must be an array." end @outputs = opts[:outputs] self.job_id = opts[:job_id] self.page = opts[:page] end |
#job_id ⇒ Integer?
Fake job ID used by executor.
100 101 102 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 100 def job_id db.job_id end |
#job_id=(value) ⇒ Object
Set fake job id value.
105 106 107 108 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 105 def job_id= value db.job_id = value page['job_id'] = value end |
#outputs ⇒ Array
Draft outputs, usually get saved after execution.
55 56 57 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 55 def outputs @outputs ||= [] end |
#page ⇒ Hash?
Current page used by executor.
112 113 114 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 112 def page @page ||= AeEasy::Core::Mock::FakeDb.build_fake_page job_id: job_id end |
#page=(value) ⇒ Object
Set current page.
117 118 119 120 121 122 123 124 125 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 117 def page= value unless value.nil? value = AeEasy::Core::Mock::FakeDb.build_page value self.job_id = value['job_id'] unless value['job_id'].nil? value['job_id'] ||= job_id db.page_gid = value['gid'] unless value['gid'].nil? end @page = value end |
#pages ⇒ Array
Draft pages, usually get saved after execution.
49 50 51 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 49 def pages @pages ||= [] end |
#save_outputs(list) ⇒ Object
Save an output collection on db.
147 148 149 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 147 def save_outputs list list.each{|output| db.outputs << output} end |
#save_pages(list) ⇒ Object
Save a page collection on db.
140 141 142 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 140 def save_pages list list.each{|page| db.pages << page} end |
#saved_outputs ⇒ Object
Retrive a list of saved outputs.
133 134 135 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 133 def saved_outputs db.outputs end |
#saved_pages ⇒ Object
Retrive a list of saved pages. Drafted pages can be included.
128 129 130 |
# File 'lib/ae_easy/core/mock/fake_executor.rb', line 128 def saved_pages db.pages end |