lib/dm-is-predefined/is/predefined.rb
#
# Finds or auto-creates the predefined resource which shares the
# given attributes.
#
# @param [Hash{Symbol => Object}] conditions
#   Query conditions.
#
# @param [Hash{Symbol => Object}] attributes
#   The attribute names and values that the predefined resource
#   should shared.
#
# @return [DataMapper::Resource, nil]
#   The predefined resource.
#
# @since 0.4.0
#
# @api public
#
Finds or auto-creates the predefined resource which shares the
given attributes.
Finds or auto - creates the predefined resource which shares the given attributes .
def first_or_predefined(conditions={},attributes=conditions)
          if (resource = first(conditions))
            return resource
          end
          attributes = predefined_attributes.values.find do |attrs|
            attrs.all? do |name,value|
              attributes.has_key?(name) && (attributes[name] == value)
            end
          end
          create(attributes) if attributes
        end
def first_or_predefined ( conditions = { } , attributes = conditions ) if ( resource = first ( conditions ) ) return resource end attributes = predefined_attributes . values . find do | attrs | attrs . all? do | name , value | attributes . has_key? ( name ) && ( attributes [ name ] == value ) end end create ( attributes ) if attributes end
Finds or auto-creates the predefined resource which shares the
given attributes.
Finds or auto - creates the predefined resource which shares the given attributes .
# if the resource wasn't found, search for matching # predefined attributes # create the resource using the predefined attributes
The predefined resource.
The predefined resource .
DataMapper::Resource, nil
conditions
<not_specific>
attributes
<not_specific>
<not_specific>
attributes The attribute names and values that the predefined resource should shared.
attributes The attribute names and values that the predefined resource should shared .
since
None
api
None