Class: Evil::Client::Settings
- Defined in:
- lib/evil/client/settings.rb
Overview
Container for settings assigned to some operation or scope.
Class Attribute Summary collapse
-
.locale ⇒ Class
readonly
Reference to the schema klass the settings belongs to.
-
.schema ⇒ Class
readonly
Reference to the schema klass the settings belongs to.
Instance Attribute Summary collapse
-
#logger ⇒ Logger?
The logger attached to current settings.
Class Method Summary collapse
-
.for(schema) ⇒ Class
Subclasses itself for a given schema.
-
.name ⇒ String
(also: to_s, to_str, inspect)
Human-friendly representation of settings class.
-
.new(logger, **op) ⇒ Evil::Client::Settings
Builds settings with options.
-
.validate(&block) ⇒ self
Add validation rule to the [#policy].
Instance Method Summary collapse
-
#datetime(value) ⇒ String?
DSL helper to format datetimes following RFC7231/RFC2822.
-
#inspect ⇒ String
(also: #to_str, #to_s)
Human-readable representation of settings instance.
-
#options ⇒ Hash<Symbol, Object>
The processed hash of options contained by the instance of settings.
Methods inherited from Model
extend, let, lets, option, options, policy
Class Attribute Details
.locale ⇒ Class (readonly)
Reference to the schema klass the settings belongs to
24 25 26 |
# File 'lib/evil/client/settings.rb', line 24 def locale @locale end |
.schema ⇒ Class (readonly)
Reference to the schema klass the settings belongs to
24 25 26 |
# File 'lib/evil/client/settings.rb', line 24 def schema @schema end |
Instance Attribute Details
#logger ⇒ Logger?
Returns The logger attached to current settings.
72 73 74 |
# File 'lib/evil/client/settings.rb', line 72 def logger @logger end |
Class Method Details
.for(schema) ⇒ Class
Subclasses itself for a given schema
14 15 16 17 18 |
# File 'lib/evil/client/settings.rb', line 14 def for(schema) Class.new(self).tap do |klass| klass.send(:instance_variable_set, :@schema, schema) end end |
.name ⇒ String Also known as: to_s, to_str, inspect
Human-friendly representation of settings class
30 31 32 |
# File 'lib/evil/client/settings.rb', line 30 def name super || @schema.to_s end |
.new(logger, **op) ⇒ Evil::Client::Settings
Builds settings with options
53 54 55 56 57 58 59 |
# File 'lib/evil/client/settings.rb', line 53 def new(logger, **op) logger&.debug(self) { "initializing with options #{op}..." } super(**op).tap do |item| item.logger = logger logger&.debug(item) { "initialized" } end end |
.validate(&block) ⇒ self
Add validation rule to the [#policy]
42 43 44 45 |
# File 'lib/evil/client/settings.rb', line 42 def validate(&block) policy.validate(&block) self end |
Instance Method Details
#datetime(value) ⇒ String?
DSL helper to format datetimes following RFC7231/RFC2822
81 82 83 84 85 86 87 88 89 |
# File 'lib/evil/client/settings.rb', line 81 def datetime(value) return unless value value = DateTime.parse(value) if value.is_a? String value = value.to_datetime if value.respond_to? :to_datetime raise "Cannot convert #{value} to DateTime" unless value.is_a?(DateTime) value.rfc2822 end |
#inspect ⇒ String Also known as: to_str, to_s
Human-readable representation of settings instance
95 96 97 98 99 |
# File 'lib/evil/client/settings.rb', line 95 def inspect number = super.match(/>:([^ ]+) /)[1] params = .map { |k, v| "@#{k}=#{v}" }.join(", ") number ? "#<#{self.class}:#{number} #{params}>" : super end |
#options ⇒ Hash<Symbol, Object>
The processed hash of options contained by the instance of settings
66 67 68 |
# File 'lib/evil/client/settings.rb', line 66 def @options ||= Options.new self.class.dry_initializer.attributes(self) end |