class LazyLazer::KeyMetadata
Simple PORO for key metadata. Yay value objects!
Attributes
default[RW]
@return [Proc, Object] the default value or generator
default_provided[W]
@return [Boolean] whether a default was provided
required[W]
@return [Boolean] whether the key must exist when creating the model
source_key[RW]
@return [Symbol] the key to fetch the value from
transform[RW]
@return [Proc, Symbol, nil] the method or proc that transforms the return value
Public Class Methods
new(key_name, *boolean_options, **options)
click to toggle source
Load attributes from a {LazyLazer::ClassMethods#property} method signature. @see LazyLazer::ClassMethods#property
# File lib/lazy_lazer/key_metadata.rb, line 25 def initialize(key_name, *boolean_options, **options) boolean_options.each_with_object(options) { |sym, hsh| hsh[sym] = true } self.source_key = options[:from] || key_name self.required = !!options[:required] self.default_provided = options.key?(:default) || options[:nil] self.transform = options[:with] self.default = options[:default] end
Public Instance Methods
default_provided?()
click to toggle source
@return [Boolean] whether no default was provided
# File lib/lazy_lazer/key_metadata.rb, line 40 def default_provided? @default_provided end
required?()
click to toggle source
@return [Boolean] whether the key must exist when creating the model
# File lib/lazy_lazer/key_metadata.rb, line 35 def required? @required end