Sha256: 25b8748a7c5b6dd5667c44c2b971510e3c25eb8f9fa8c2213f84e25694c2bf3e
Contents?: true
Size: 1.95 KB
Versions: 1
Compression:
Stored size: 1.95 KB
Contents
require 'sparkle_formation' require 'attribute_struct/monkey_camels' class SparkleFormation # SparkleFormation customized AttributeStruct class SparkleStruct < AttributeStruct include ::SparkleFormation::SparkleAttribute # @!parse include ::SparkleFormation::SparkleAttribute # Override initializer to force desired behavior def initialize(*_) super @_camel_keys = true _set_state :hash_load_struct => true end # Set SparkleFormation instance # # @param inst [SparkleFormation] # @return [SparkleFormation] def _set_self(inst) unless(inst.is_a?(::SparkleFormation)) ::Kernel.raise ::TypeError.new "Expecting type of `SparkleFormation` but got `#{inst.class}`" end @self = inst end # @return [SparkleFormation] def _self(*_) unless(@self) if(_parent.nil?) ::Kernel.raise ::ArgumentError.new 'Creator did not provide return reference!' else _parent._self end else @self end end # @return [Class] def _klass ::SparkleFormation::SparkleStruct end # Instantiation override properly set origin template # # @return [SparkleStruct] def _klass_new(*args, &block) inst = super() inst._set_self(_self) if(args.first.is_a?(::Hash)) inst._load(args.first) end if(block) inst.build!(&block) end inst end # Override the state to force helpful error when no value has been # provided # # @param arg [String, Symbol] name of parameter # @return [Object] # @raises [ArgumentError] def _state(arg) result = super if(@self && result.nil?) if(_self.parameters.keys.map(&:to_s).include?(arg.to_s)) ::Kernel.raise ::ArgumentError.new "No value provided for compile time parameter: `#{arg}`!" end end result end alias_method :state!, :_state end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sparkle_formation-1.1.14 | lib/sparkle_formation/sparkle_struct.rb |