app/models/unidom/article_number/marking.rb in unidom-article_number-1.0 vs app/models/unidom/article_number/marking.rb in unidom-article_number-1.1
- old
+ new
@@ -13,22 +13,31 @@
scope :barcode_is, ->(barcode) { where barcode: barcode }
scope :marked_by, ->(marker) { where marker: marker }
scope :marked_is, ->(marked) { where marked: marked }
def self.mark(barcode: nil, marked: nil, marker: nil, opened_at: Time.now)
+ self.mark! barcode: barcode, marked: marked, marker: marker, opened_at: opened_at
+ end
- raise ArgumentError.new('Barcode is required.') if barcode.blank?
- raise ArgumentError.new('Marked is required.' ) if marked.blank?
+ def self.mark!(barcode: nil, marked: nil, marker: nil, opened_at: Time.now)
+ 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?
+
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
+
+ class << self
+ deprecate mark: :mark!, deprecator: ActiveSupport::Deprecation.new('2.0', 'unidom-article_number')
end
end