Class: Remont::Schema
- Inherits:
-
Object
- Object
- Remont::Schema
- Defined in:
- lib/remont/schema.rb
Constant Summary collapse
- MISSING_PROCESSING_STATUS_ATTR =
"Processing status attribute isn't configured".freeze
Instance Attribute Summary collapse
Instance Method Summary collapse
- #after(&block) ⇒ Remont::Schema
- #attribute ⇒ Remont::Schema
- #before(&block) ⇒ Remont::Schema
-
#initialize(opts = {}, &block) ⇒ Schema
constructor
A new instance of Schema.
- #process! ⇒ Any
- #scope(&scope) ⇒ Remont::Schema
- #with_process_timestamp_attribute(attr_name) ⇒ Remont::Schema
- #without_processed ⇒ Remont::Schema
Constructor Details
#initialize(opts = {}, &block) ⇒ Schema
Returns a new instance of Schema.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/remont/schema.rb', line 16 def initialize(opts = {}, &block) @model = opts.fetch(:model) @model_scope = opts.fetch(:scope, default_scope) @without_processed_scope = default_scope @process_timestamp_attribute = opts.fetch(:process_timestamp_attribute, Remont.config.) @before_cb = nil @after_cb = nil @attributes = [] instance_eval(&block) end |
Instance Attribute Details
#attributes ⇒ Array<Remont::Attribute> (readonly)
6 7 8 |
# File 'lib/remont/schema.rb', line 6 def attributes @attributes end |
#process_timestamp_attribute ⇒ Nil, ... (readonly)
9 10 11 |
# File 'lib/remont/schema.rb', line 9 def @process_timestamp_attribute end |
Instance Method Details
#after(&block) ⇒ Remont::Schema
74 75 76 77 78 |
# File 'lib/remont/schema.rb', line 74 def after(&block) @after_cb = block self end |
#attribute ⇒ Remont::Schema
58 59 60 61 62 |
# File 'lib/remont/schema.rb', line 58 def attribute(...) @attributes << Attribute.new(...) self end |
#before(&block) ⇒ Remont::Schema
66 67 68 69 70 |
# File 'lib/remont/schema.rb', line 66 def before(&block) @before_cb = block self end |
#process! ⇒ Any
81 82 83 |
# File 'lib/remont/schema.rb', line 81 def process! records_for_processing.find_each { |record| processor.process!(record) } end |
#scope(&scope) ⇒ Remont::Schema
47 48 49 50 51 |
# File 'lib/remont/schema.rb', line 47 def scope(&scope) @model_scope = scope self end |
#with_process_timestamp_attribute(attr_name) ⇒ Remont::Schema
39 40 41 42 43 |
# File 'lib/remont/schema.rb', line 39 def (attr_name) @process_timestamp_attribute = attr_name self end |
#without_processed ⇒ Remont::Schema
29 30 31 32 33 34 35 |
# File 'lib/remont/schema.rb', line 29 def without_processed raise MISSING_PROCESSING_STATUS_ATTR if @process_timestamp_attribute.nil? @without_processed_scope = proc { |scope| scope.where( => nil) } self end |