app/models/unidom/article_number/marking.rb in unidom-article_number-3.0 vs app/models/unidom/article_number/marking.rb in unidom-article_number-3.0.1

- old
+ new

@@ -1,36 +1,42 @@ ## # Marking 是条码和物品的标记关系。 -class Unidom::ArticleNumber::Marking < Unidom::ArticleNumber::ApplicationRecord +module Unidom + module ArticleNumber - self.table_name = 'unidom_markings' + class Marking < ApplicationRecord - include Unidom::Common::Concerns::ModelExtension + self.table_name = 'unidom_markings' - belongs_to :barcode, polymorphic: true - belongs_to :marked, polymorphic: true - belongs_to :marker, polymorphic: true + include Unidom::Common::Concerns::ModelExtension - scope :barcode_is, ->(barcode) { where barcode: barcode } - scope :marked_by, ->(marker) { where marker: marker } - scope :marked_is, ->(marked) { where marked: marked } + belongs_to :barcode, polymorphic: true + belongs_to :marked, polymorphic: true + belongs_to :marker, polymorphic: true - def self.mark!(barcode: nil, marked: nil, marker: nil, opened_at: Time.now) + scope :barcode_is, ->(barcode) { where barcode: barcode } + scope :marked_by, ->(marker) { where marker: marker } + scope :marked_is, ->(marked) { where marked: marked } - raise ArgumentError.new('The barcode argument is required.' ) if barcode.blank? - raise ArgumentError.new('The marked argument is required.' ) if marked.blank? - raise ArgumentError.new('The opened_at argument is required.') if opened_at.blank? + def self.mark!(barcode: nil, marked: nil, marker: nil, opened_at: Time.now) - query = barcode_is(barcode).marked_is(marked).valid_at.alive - creation = { opened_at: opened_at } - if marker.present? && marker.respond_to?(:id) - creation[:marker] = marker - else - creation[:marker_id] = Unidom::Common::NULL_UUID - creation[:marker_type] = '' - end - query.first_or_create! creation + raise ArgumentError.new('The barcode argument is required.' ) if barcode.blank? + raise ArgumentError.new('The marked argument is required.' ) if marked.blank? + raise ArgumentError.new('The opened_at argument is required.') if opened_at.blank? - end + query = barcode_is(barcode).marked_is(marked).valid_at.alive + creation = { opened_at: opened_at } + if marker.present? && marker.respond_to?(:id) + creation[:marker] = marker + else + creation[:marker_id] = Unidom::Common::NULL_UUID + creation[:marker_type] = '' + end + query.first_or_create! creation -end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::ArticleNumber::Marking' + end + + end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::ArticleNumber::Marking' + + end +end