lib/ui_rules.rb
# Get an OpenStruct with keys for every attribute of an entity.
# Optionally include values for some attributes in the merge_hash.
#
# @param struct [DryStruct] the entity to base the struct on.
# @param merge_hash [hash] optional hash to merge with non-nil values.
# @return [OpenStruct]
Get an OpenStruct with keys for every attribute of an entity.
Optionally include values for some attributes in the merge_hash.
Get an OpenStruct with keys for every attribute of an entity . Optionally include values for some attributes in the merge_hash .
def new_form_object_from_struct(struct, merge_hash: {})
      cols = struct.attribute_names.reject { |c| %i[id created_at updated_at].include?(c) }
      hash = Hash[cols.zip([nil] * cols.length)]
      OpenStruct.new(hash.merge(merge_hash))
    end
def new_form_object_from_struct ( struct , merge_hash : { } ) cols = struct . attribute_names . reject { | c | %i[ id created_at updated_at ] . include? ( c ) } hash = Hash [ cols . zip ( [ nil ] * cols . length ) ] OpenStruct . new ( hash . merge ( merge_hash ) ) end
Get an OpenStruct with keys for every attribute of an entity.
Get an OpenStruct with keys for every attribute of an entity .
None
OpenStruct
struct
the entity to base the struct on.
the entity to base the struct on .
merge_hash
optional hash to merge with non-nil values.
optional hash to merge with non - nil values .