Class: AnalyticsOps::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/analytics_ops/snapshot.rb,
sig/analytics_ops.rbs

Overview

Normalized remote state. No generated Google objects escape into this value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property:, streams:, retention:, key_events:, custom_dimensions:, custom_metrics:) ⇒ Snapshot

Returns a new instance of Snapshot.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/analytics_ops/snapshot.rb', line 10

def initialize(property:, streams:, retention:, key_events:, custom_dimensions:, custom_metrics:)
  unless property.is_a?(Resources::Property)
    raise ArgumentError, "property must be an AnalyticsOps::Resources::Property"
  end
  unless retention.nil? || retention.is_a?(Resources::Retention)
    raise ArgumentError, "retention must be an AnalyticsOps::Resources::Retention or nil"
  end

  @property = property
  @streams = sorted_resources(streams, Resources::DataStream, "streams", &:id)
  @retention = retention
  @key_events = sorted_resources(key_events, Resources::KeyEvent, "key_events", &:event_name)
  @custom_dimensions = sorted_resources(
    custom_dimensions, Resources::CustomDimension, "custom_dimensions"
  ) do |item|
    [item.scope, item.parameter_name]
  end
  @custom_metrics = sorted_resources(custom_metrics, Resources::CustomMetric, "custom_metrics", &:parameter_name)
  freeze
end

Instance Attribute Details

#custom_dimensionsArray[Resources::CustomDimension] (readonly)

Returns the value of attribute custom_dimensions.

Returns:



8
9
10
# File 'lib/analytics_ops/snapshot.rb', line 8

def custom_dimensions
  @custom_dimensions
end

#custom_metricsArray[Resources::CustomMetric] (readonly)

Returns the value of attribute custom_metrics.

Returns:



8
9
10
# File 'lib/analytics_ops/snapshot.rb', line 8

def custom_metrics
  @custom_metrics
end

#key_eventsArray[Resources::KeyEvent] (readonly)

Returns the value of attribute key_events.

Returns:



8
9
10
# File 'lib/analytics_ops/snapshot.rb', line 8

def key_events
  @key_events
end

#propertyResources::Property (readonly)

Returns the value of attribute property.

Returns:



8
9
10
# File 'lib/analytics_ops/snapshot.rb', line 8

def property
  @property
end

#retentionResources::Retention? (readonly)

Returns the value of attribute retention.

Returns:



8
9
10
# File 'lib/analytics_ops/snapshot.rb', line 8

def retention
  @retention
end

#streamsArray[Resources::DataStream] (readonly)

Returns the value of attribute streams.

Returns:



8
9
10
# File 'lib/analytics_ops/snapshot.rb', line 8

def streams
  @streams
end

Instance Method Details

#fingerprintString

Returns:

  • (String)


46
47
48
# File 'lib/analytics_ops/snapshot.rb', line 46

def fingerprint
  Canonical.fingerprint(to_h)
end

#property_idString

Returns:

  • (String)


31
32
33
# File 'lib/analytics_ops/snapshot.rb', line 31

def property_id
  property.id
end

#to_hrecord

Returns:

  • (record)


35
36
37
38
39
40
41
42
43
44
# File 'lib/analytics_ops/snapshot.rb', line 35

def to_h
  {
    "property" => property.to_h,
    "streams" => streams.map(&:to_h),
    "retention" => retention&.to_h,
    "key_events" => key_events.map(&:to_h),
    "custom_dimensions" => custom_dimensions.map(&:to_h),
    "custom_metrics" => custom_metrics.map(&:to_h)
  }
end