Class: Google::Cloud::Bigquery::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/bigquery/condition.rb

Overview

Condition

Represents a textual expression in the Common Expression Language (CEL) syntax. CEL is a C-like expression language. The syntax and semantics of CEL are documented at https://github.com/google/cel-spec

Used to define condition for Dataset::Access rules

Instance Method Summary collapse

Constructor Details

#initialize(expression, description: nil, location: nil, title: nil) ⇒ Condition

Create a new Condition object.

Examples:

condition = Google::Cloud::Bigquery::Condition.new(
  "document.summary.size() < 100",
  description: "Determines if a summary is less than 100 chars",
  location: "document/summary",
  title: "Summary size limit"
)

Parameters:

  • expression (String)

    The expression in CEL syntax.

  • description (String) (defaults to: nil)

    Optional description of the expression.

  • location (String) (defaults to: nil)

    Optional location of the expression for error reporting.

  • title (String) (defaults to: nil)

    Optional title for the expression.

Raises:

  • (ArgumentError)

    if expression is nil or empty.

See Also:



184
185
186
187
188
189
190
191
192
# File 'lib/google/cloud/bigquery/condition.rb', line 184

def initialize expression, description: nil, location: nil, title: nil
  if expression.nil? || expression.strip.empty?
    raise ArgumentError, "Expression cannot be nil or empty"
  end
  @expression = expression
  @description = description
  @location = location
  @title = title
end

Instance Method Details

#descriptionString?

Returns the optional description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI.

Examples:

condition = Google::Cloud::Bigquery::Condition.new(
  "document.summary.size() < 100",
  description: "Checks if summary is less than 100 chars"
)
puts condition.description # => "Checks if summary is less than 100 chars"

Returns:

  • (String, nil)

    The description of the condition. nil if not set.



78
79
80
# File 'lib/google/cloud/bigquery/condition.rb', line 78

def description
  @description
end

#description=(val) ⇒ Object

Sets the optional description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI.

Examples:

condition = Google::Cloud::Bigquery::Condition.new(
  "document.summary.size() < 100"
)
condition.description = "Checks if summary is less than 100 chars"

Parameters:

  • val (String, nil)

    The description to set. nil to unset.



94
95
96
# File 'lib/google/cloud/bigquery/condition.rb', line 94

def description= val
  @description = val
end

#expressionString

Returns the textual representation of an expression in Common Expression Language syntax.

Examples:

condition = Google::Cloud::Bigquery::Condition.new(
  "resource.name.startsWith('projects/my-project')"
)
puts condition.expression # => "resource.name.startsWith('projects/my-project')"

Returns:

  • (String)

    The expression of the condition.



41
42
43
# File 'lib/google/cloud/bigquery/condition.rb', line 41

def expression
  @expression
end

#expression=(val) ⇒ Object

Sets the textual representation of an expression in Common Expression Language syntax.

Examples:

condition = Google::Cloud::Bigquery::Condition.new(
  "resource.name.startsWith('projects/my-project')"
)
condition.expression = "document.summary.size() < 100"

Parameters:

  • val (String)

    The expression to set.

Raises:

  • (ArgumentError)

    if the expression is nil or empty.



58
59
60
61
62
63
# File 'lib/google/cloud/bigquery/condition.rb', line 58

def expression= val
  if val.nil? || val.strip.empty?
    raise ArgumentError, "Expression cannot be nil or empty"
  end
  @expression = val
end

#locationString?

Returns the optional string indicating the location of the expression for error reporting, e.g. a file name and a position in the file.

Examples:

condition = Google::Cloud::Bigquery::Condition.new(
  "document.summary.size() < 100",
  location: "document/summary"
)
puts condition.location # => "document/summary"

Returns:

  • (String, nil)

    The location of the condition. nil if not set.



111
112
113
# File 'lib/google/cloud/bigquery/condition.rb', line 111

def location
  @location
end

#location=(val) ⇒ Object

Sets the optional string indicating the location of the expression for error reporting, e.g. a file name and a position in the file.

Examples:

condition = Google::Cloud::Bigquery::Condition.new(
  "document.summary.size() < 100"
)
condition.location = "document/summary"

Parameters:

  • val (String, nil)

    The location to set. nil to unset.



127
128
129
# File 'lib/google/cloud/bigquery/condition.rb', line 127

def location= val
  @location = val
end

#titleString?

Returns the optional title for the expression, i.e. a short string describing its purpose. This can be used e.g. in UIs which allow to enter the expression.

Examples:

condition = Google::Cloud::Bigquery::Condition.new(
  "document.summary.size() < 100",
  title: "Summary size limit"
)
puts condition.title # => "Summary size limit"

Returns:

  • (String, nil)

    The title of the condition. nil if not set.



144
145
146
# File 'lib/google/cloud/bigquery/condition.rb', line 144

def title
  @title
end

#title=(val) ⇒ Object

Sets the optional title for the expression, i.e. a short string describing its purpose. This can be used e.g. in UIs which allow to enter the expression.

Examples:

condition = Google::Cloud::Bigquery::Condition.new(
  "document.summary.size() < 100"
)
condition.title = "Summary size limit"

Parameters:

  • val (String, nil)

    The title to set. nil to unset.



160
161
162
# File 'lib/google/cloud/bigquery/condition.rb', line 160

def title= val
  @title = val
end