Class: ElasticGraph::SchemaArtifacts::RuntimeMetadata::DynamicParam

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/schema_artifacts/runtime_metadata/params.rb

Overview

Represents metadata about dynamic params we pass to our update scripts.

Constant Summary collapse

SOURCE_PATH =
"source_path"
CARDINALITY =
"cardinality"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hash(hash, name) ⇒ Object



38
39
40
41
42
43
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/params.rb', line 38

def self.from_hash(hash, name)
  new(
    source_path: hash[SOURCE_PATH] || name,
    cardinality: hash.fetch(CARDINALITY).to_sym
  )
end

Instance Method Details

#to_dumpable_hash(param_name) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/params.rb', line 45

def to_dumpable_hash(param_name)
  {
    # Keys here are ordered alphabetically; please keep them that way.
    CARDINALITY => cardinality.to_s,
    SOURCE_PATH => (source_path if source_path != param_name)
  }
end

#value_for(event_or_prepared_record) ⇒ Object



53
54
55
56
57
58
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/params.rb', line 53

def value_for(event_or_prepared_record)
  case cardinality
  when :many then Support::HashUtil.fetch_leaf_values_at_path(event_or_prepared_record, source_path) { [] }
  when :one then Support::HashUtil.fetch_value_at_path(event_or_prepared_record, source_path) { nil }
  end
end