Module: Sail

Defined in:
lib/sail.rb,
lib/sail/types.rb,
lib/sail/engine.rb,
lib/sail/graphql.rb,
lib/sail/railtie.rb,
lib/sail/version.rb,
lib/sail/mutations.rb,
lib/sail/types/set.rb,
lib/sail/types/uri.rb,
lib/sail/types/cron.rb,
lib/sail/types/date.rb,
lib/sail/types/type.rb,
lib/sail/types/array.rb,
lib/sail/types/float.rb,
lib/sail/types/range.rb,
app/models/sail/entry.rb,
lib/sail/instrumenter.rb,
lib/sail/types/string.rb,
lib/sail/configuration.rb,
lib/sail/types/ab_test.rb,
lib/sail/types/boolean.rb,
lib/sail/types/integer.rb,
lib/sail/types/locales.rb,
app/models/sail/profile.rb,
app/models/sail/setting.rb,
lib/sail/types/throttle.rb,
lib/sail/types/obj_model.rb,
lib/sail/constant_collection.rb,
app/models/sail/application_record.rb,
app/helpers/sail/application_helper.rb,
app/controllers/sail/profiles_controller.rb,
app/controllers/sail/settings_controller.rb,
app/controllers/sail/application_controller.rb,
lib/generators/sail/update/update_generator.rb,
lib/generators/sail/install/install_generator.rb

Overview

:nocov:

Defined Under Namespace

Modules: ApplicationHelper, ConstantCollection, Generators, Graphql, Types Classes: ApplicationController, ApplicationRecord, Configuration, Engine, Entry, Instrumenter, Profile, ProfilesController, Railtie, Setting, SettingsController

Constant Summary collapse

VERSION =
"3.3.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



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

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



84
85
86
# File 'lib/sail.rb', line 84

def configure
  yield(configuration)
end

.get(name, expected_errors: []) ⇒ Object

Gets the value of a setting casted with the appropriate type. Can be used with a block.

Response is cached until the setting’s value is updated or until the time specific in the configuration expires.

Examples:

Sail.get(“my_setting”)

> true

Sail.get(“my_setting”) do |setting_value|

execute_code if setting_value

end



32
33
34
35
36
37
38
39
# File 'lib/sail.rb', line 32

def get(name, expected_errors: [])
  setting_value = Sail::Setting.get(name)

  block_given? ? yield(setting_value) : setting_value
rescue StandardError => e
  instrumenter.increment_failure_of(name) unless expected_errors.blank? || expected_errors.include?(e.class)
  raise e
end

.instrumenterObject



88
89
90
# File 'lib/sail.rb', line 88

def instrumenter
  @instrumenter ||= Instrumenter.new
end

.reset(name) ⇒ Object

Resets the value of a setting

Restores the original value defined in config/sail.yml



61
62
63
# File 'lib/sail.rb', line 61

def reset(name)
  Sail::Setting.reset(name)
end

.set(name, value) ⇒ Object

Sets the value of a setting

Updating a setting’s value will cause its cache to expire.

Passed values are cast to string before saving to the database. For instance, the statement below will appropriately update the setting value to “true”.

Sail.set(:boolean_setting, true)



53
54
55
# File 'lib/sail.rb', line 53

def set(name, value)
  Sail::Setting.set(name, value)
end

.switcher(positive:, negative:, throttled_by:) ⇒ Object

Switches between the value of two settings randomly

throttled_by: a throttle type setting positive: a setting to be returned when the throttle returns true negative: a setting to be returned when the throttle returns false

Based on the throttled_by setting, this method will return either the value of positive or negative.

If throttled_by returns true, the casted value of positive is returned. When false, the casted value of negative is returned.



76
77
78
# File 'lib/sail.rb', line 76

def switcher(positive:, negative:, throttled_by:)
  Sail::Setting.switcher(positive: positive, negative: negative, throttled_by: throttled_by)
end