Class: Metacrunch::Job
- Inherits:
-
Object
- Object
- Metacrunch::Job
- Defined in:
- lib/metacrunch/job.rb
Overview
Defined Under Namespace
Instance Attribute Summary collapse
-
#dsl ⇒ Object
readonly
Returns the value of attribute dsl.
Class Method Summary collapse
Instance Method Summary collapse
- #add_transformation(callable, buffer_size: nil, buffer: nil) ⇒ Object
- #destination ⇒ Object
- #destination=(destination) ⇒ Object
-
#initialize(file_content = nil, &block) ⇒ Job
constructor
A new instance of Job.
- #post_process ⇒ Object
- #post_process=(callable) ⇒ Object
- #pre_process ⇒ Object
- #pre_process=(callable) ⇒ Object
- #run ⇒ Object
- #source ⇒ Object
- #source=(source) ⇒ Object
- #transformations ⇒ Object
Constructor Details
#initialize(file_content = nil, &block) ⇒ Job
Returns a new instance of Job.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/metacrunch/job.rb', line 13 def initialize(file_content = nil, &block) @dsl = Dsl.new(self) @deprecator = ActiveSupport::Deprecation.new("5.0.0", "metacrunch") if file_content @dsl.instance_eval(file_content, "Check your metacrunch Job at Line") elsif block_given? @dsl.instance_eval(&block) end end |
Instance Attribute Details
#dsl ⇒ Object (readonly)
Returns the value of attribute dsl.
5 6 7 |
# File 'lib/metacrunch/job.rb', line 5 def dsl @dsl end |
Class Method Details
.define(file_content = nil, &block) ⇒ Object
8 9 10 |
# File 'lib/metacrunch/job.rb', line 8 def define(file_content = nil, &block) self.new(file_content, &block) end |
Instance Method Details
#add_transformation(callable, buffer_size: nil, buffer: nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/metacrunch/job.rb', line 65 def add_transformation(callable, buffer_size: nil, buffer: nil) ensure_callable!(callable) if buffer_size && buffer_size.is_a?(Numeric) @deprecator.deprecation_warning(:buffer_size, :buffer) buffer = buffer_size end if buffer transformations << Metacrunch::Job::Buffer.new(buffer) end transformations << callable end |
#destination ⇒ Object
34 35 36 |
# File 'lib/metacrunch/job.rb', line 34 def destination @destination end |
#destination=(destination) ⇒ Object
38 39 40 41 |
# File 'lib/metacrunch/job.rb', line 38 def destination=(destination) ensure_destination!(destination) @destination = destination end |
#post_process ⇒ Object
52 53 54 |
# File 'lib/metacrunch/job.rb', line 52 def post_process @post_process end |
#post_process=(callable) ⇒ Object
56 57 58 59 |
# File 'lib/metacrunch/job.rb', line 56 def post_process=(callable) ensure_callable!(callable) @post_process = callable end |
#pre_process ⇒ Object
43 44 45 |
# File 'lib/metacrunch/job.rb', line 43 def pre_process @pre_process end |
#pre_process=(callable) ⇒ Object
47 48 49 50 |
# File 'lib/metacrunch/job.rb', line 47 def pre_process=(callable) ensure_callable!(callable) @pre_process = callable end |
#run ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/metacrunch/job.rb', line 80 def run run_pre_process if source # Run transformation for each data object available in source source.each do |data| data = run_transformations(transformations, data) write_destination(data) end # Run all transformations a last time to flush existing buffers data = run_transformations(transformations, nil, flush_buffers: true) write_destination(data) # Close destination destination.close if destination end run_post_process self end |
#source ⇒ Object
25 26 27 |
# File 'lib/metacrunch/job.rb', line 25 def source @source end |
#source=(source) ⇒ Object
29 30 31 32 |
# File 'lib/metacrunch/job.rb', line 29 def source=(source) ensure_source!(source) @source = source end |
#transformations ⇒ Object
61 62 63 |
# File 'lib/metacrunch/job.rb', line 61 def transformations @transformations ||= [] end |