Class: LcpRuby::BackgroundJobs::ContractValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/background_jobs/contract_validator.rb

Constant Summary collapse

REQUIRED_FIELDS =
{
  "job_type" => "string",
  "status" => "enum",
  "progress" => "integer"
}.freeze
{
  "error_message" => "text",
  "log" => %w[json jsonb],
  "params" => %w[json jsonb],
  "target_model" => "string",
  "target_id" => "integer",
  "started_at" => "datetime",
  "last_attempt_at" => "datetime",
  "completed_at" => "datetime",
  "scheduled_at" => "datetime",
  "cancellation_requested" => "boolean",
  "triggered_by_id" => "integer",
  "triggered_by_snapshot" => %w[json jsonb],
  "unique_key" => "string",
  "active_job_id" => "string",
  "attempt" => "integer"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_def, field_mapping = nil) ⇒ ContractValidator

Returns a new instance of ContractValidator.



32
33
34
35
36
37
# File 'lib/lcp_ruby/background_jobs/contract_validator.rb', line 32

def initialize(model_def, field_mapping = nil)
  @model_def = model_def
  @field_mapping = (field_mapping || default_field_mapping).transform_keys(&:to_s)
  @errors = []
  @warnings = []
end

Class Method Details

.validate(model_def, field_mapping = nil) ⇒ Object



28
29
30
# File 'lib/lcp_ruby/background_jobs/contract_validator.rb', line 28

def self.validate(model_def, field_mapping = nil)
  new(model_def, field_mapping).validate
end

Instance Method Details

#validateObject



39
40
41
42
43
44
# File 'lib/lcp_ruby/background_jobs/contract_validator.rb', line 39

def validate
  validate_required_fields
  validate_recommended_fields

  Metadata::ContractResult.new(errors: @errors, warnings: @warnings)
end