class BeerDb::Model::Brand

Private Class Methods

create_or_update_from_attribs( attribs, values ) click to toggle source
# File lib/beerdb/models/brand.rb, line 36
def self.create_or_update_from_attribs( attribs, values )

  ## fix: add/configure logger for ActiveRecord!!!
  logger = LogKernel::Logger.root

  ## check for grades (e.g. ***/**/*) in titles (will add attribs[:grade] to hash)
  ## if grade missing; set default to 4; lets us update overwrite 1,2,3 values on update
  attribs[:grade] ||= 4

  rec = Brand.find_by_key( attribs[:key] )

  if rec.present?
    logger.debug "update Brand #{rec.id}-#{rec.key}:"
  else
    logger.debug "create Brand:"
    rec = Brand.new
  end

  logger.debug attribs.to_json

  rec.update_attributes!( attribs )
end
create_or_update_from_title( title, more_attribs = {} ) click to toggle source

convenience helper Brand.create_or_update_from_title

# File lib/beerdb/models/brand.rb, line 30
def self.create_or_update_from_title( title, more_attribs = {} )
  values = [title]
  Brand.create_or_update_from_values( values, more_attribs )
end
create_or_update_from_values( values, more_attribs = {} ) click to toggle source
# File lib/beerdb/models/brand.rb, line 22
def self.create_or_update_from_values( values, more_attribs = {} )
  attribs, more_values = find_key_n_title( values )
  attribs = attribs.merge( more_attribs )

  Brand.create_or_update_from_attribs( attribs, more_values )
end