Module: Stellwerk

Defined in:
lib/stellwerk.rb,
lib/stellwerk/flow.rb,
lib/stellwerk/errors.rb,
lib/stellwerk/result.rb,
lib/stellwerk/license.rb,
lib/stellwerk/version.rb,
lib/stellwerk/metering.rb,
lib/stellwerk/evaluator.rb,
lib/stellwerk/functions.rb,
lib/stellwerk/api_client.rb,
lib/stellwerk/configuration.rb

Overview

Collection & aggregation helper functions for Dentaku. We override common aggregators (SUM, COUNT, MIN, MAX) to be dual-mode:

  • Classic Dentaku usage: SUM(a, b, c)
  • Array mode: SUM(array) or SUM(array_of_numbers) or SUM(array_of_mixed) Additional functions: FIRST, LAST, TAKE, PROJECT (internal helper) Projection pattern: identifier.field is preprocessed into PROJECT(identifier, "field") Mixed-type coercion:
  • Numeric values kept
  • Numeric-looking strings converted to Float
  • nil ignored
  • Other types ignored for numeric aggregations
  • If no numeric values remain -> SUM = 0, MIN/MAX = nil, COUNT counts all non-nil projected elements (not just numeric) TAKE(array, n) -> first n elements (n coerced to integer, negative treated as 0) FIRST(array) / LAST(array) -> element or nil

Defined Under Namespace

Modules: Functions Classes: ApiClient, ApiError, Configuration, Error, EvaluationError, Evaluator, Flow, InvalidFlowError, License, LicenseError, Metering, MissingInputError, QuotaExceededError, Result, SubFlowNotFoundError

Constant Summary collapse

VERSION =
"0.2.1"

Class Method Summary collapse

Class Method Details

.api_key=(key) ⇒ Object

Convenience setter for API key

Parameters:

  • key (String) —

    The API key



66
67
68
# File 'lib/stellwerk.rb', line 66

def api_key=(key)
  configuration.api_key = key
end

.configuration ⇒ Configuration

Returns the configuration instance

Returns:



47
48
49
# File 'lib/stellwerk.rb', line 47

def configuration
  @configuration ||= Configuration.new
end

.configure {|Configuration| ... } ⇒ Object

Configure Stellwerk

Examples:

Stellwerk.configure do |config|
  config.api_key = 'sk_stellwerk_...'
  config.logger = Logger.new(STDOUT)
end

Yields:



59
60
61
# File 'lib/stellwerk.rb', line 59

def configure
  yield configuration
end

.license ⇒ License

Returns the license instance

Returns:



87
88
89
# File 'lib/stellwerk.rb', line 87

def license
  @license ||= License.new
end

.licensed? ⇒ Boolean

Check if the SDK is properly licensed

Validates the API key on first call and caches the result.

Returns:

  • (Boolean)


103
104
105
106
107
108
109
# File 'lib/stellwerk.rb', line 103

def licensed?
  return false unless configuration.api_key?

  license.valid? || license.validate!
rescue LicenseError, ApiError
  false
end

.logger ⇒ Logger

Returns the configured logger (defaults to a null logger)

Returns:

  • (Logger)


73
74
75
# File 'lib/stellwerk.rb', line 73

def logger
  configuration.logger || @default_logger ||= Logger.new(File::NULL)
end

.logger=(logger) ⇒ Object

Set the logger

Parameters:

  • logger (Logger)


80
81
82
# File 'lib/stellwerk.rb', line 80

def logger=(logger)
  configuration.logger = logger
end

.metering ⇒ Metering

Returns the metering instance

Returns:



94
95
96
# File 'lib/stellwerk.rb', line 94

def metering
  @metering ||= Metering.new
end

.reset! ⇒ Object

Reset all state to defaults

Resets configuration, license, and metering state.



114
115
116
117
118
119
120
121
# File 'lib/stellwerk.rb', line 114

def reset!
  metering.reset!
  license.reset!
  @configuration = nil
  @license = nil
  @metering = nil
  @default_logger = nil
end