## # /lib/skn_utils/nested_result_base.rb # # Creates an Object with instance variables and associated getters and setters for hash each input key. # If the key's value is also a hash itself, it too will become an Object. # if the key's value is a Array of Hashes, each element of the Array will become an Object. # # This nesting action is controlled by the value of the option key ':depth'. # The key :depth defaults to :multi, an has options of :single, or :multi_with_arrays # # The ability of the resulting Object to be Marshalled(dump/load) can be preserved by merging # into the input params key ':enable_serialization' set to true. It defaults to false for speed purposes # ## # Operational Options # -------------------------------- # :enable_serialization = false -- [ true | false ], for speed, omits creation of attr_accessor # :depth = :multi -- [ :single | :multi | :multi_with_arrays ] ## # Public Components # -------------------------------- # Inherit from NestedResultBase # or Include AttributeHelpers ## # # Basic function includes: # - provides the hash or dot notation methods of accessing values from object created; i.e # 'obj = ResultBean.new({value1: "some value", value2: {one: 1, two: "two"}}) # 'x = obj.value1' or 'x = obj.value2.one' # 'x = obj["value1"]' # 'x = obj[:value1]' # # - enables serialization by avoiding the use of 'singleton_class' methods which breaks Serializers # Serializer supports xml, json, hash, and standard Marshall'ing # # person = PageControls.new({name: "Bob"}) # person.attributes # => {"name"=>"Bob"} # person.serializable_hash # => {"name"=>"Bob"} # person.to_hash # => {"name"=>"Bob"} # person.to_json # => "{\"name\":\"Bob\"}" # person.to_xml # => "\n\n Bob\n\n" # dmp = Marshal.dump(person) # => "\x04\bo:\x1ASknUtils::PageControls\x06:\n@nameI\"\bBob\x06:\x06ET" # person = Marshal.load(dmp) # => # # # ***GenericBean designed to automatically handle the setup for serialization and multi level without arrays # # - post create additions: # 'obj = ResultBean.new({value1: "some value", value2: {one: 1, two: "two"}}) # 'x = obj.one' --causes NoMethodError # 'x = obj.one = 'some other value' --creates a new instance value with accessors # 'x = obj.one = {key1: 1, two: "two"}' --creates a new ***bean as the value of obj.one # 'y = obj.one.two' --returns "two" # 'y = obj.one[:two] --returns "two" # 'y = obj.one['two'] --returns "two" # # - supports predicates ? and clear_? method patterns # 'obj = PageControls.new({name: "Something", phone: "2604815365"})' # 'obj.name?' # => true true or false, like obj.name.present? # 'obj.clear_name' # => nil sets :name to nil # ## # The combination of this NestedResultBase(dot notation class) and AttributeHelpers(hash notation module), produces # this effect from an input hash: # # {:depth =>