unidom-article_number 1.0 → 1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/app/models/unidom/article_number/concerns/as_barcode.rb +12 -0
- data/app/models/unidom/article_number/concerns/as_marked.rb +11 -0
- data/app/models/unidom/article_number/ean13_barcode.rb +3 -4
- data/app/models/unidom/article_number/ean8_barcode.rb +4 -4
- data/app/models/unidom/article_number/marking.rb +11 -2
- data/lib/unidom/article_number/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e103c694c4ed80ec65b731cda49a3e0783e0b437
|
|
4
|
+
data.tar.gz: 6fc564bfd5fdaeef8c35500e6304c5ec989a7f48
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 72a46da309964735cbd859632f7fbef9cbc52ae82130e7737ae3c676513bd697f328e9b065116514e8cfa685b65ac89e8126f3e77187003142e3f526afe468d5
|
|
7
|
+
data.tar.gz: 0c183c6d24e22f7cf1217dbe5c30f28a404078ef37ddf71c76f37e613a7088c6a27c6fc3c8f826d32418cf180d299c77a48fbd621bfa0893412981176f1c330c
|
data/README.md
CHANGED
|
@@ -32,3 +32,17 @@ marker = Person.create name: 'John'
|
|
|
32
32
|
ean_13_marking = Unidom::ArticleNumber::Marking.barcode_is(ean_13_barcode).marked_is(marked).first_or_create marker: marker, opened_at: Time.now
|
|
33
33
|
ean_8_marking = Unidom::ArticleNumber::Marking.barcode_is(ean_8_barcode).marked_is(marked).first_or_create marker: marker, opened_at: Time.now
|
|
34
34
|
```
|
|
35
|
+
|
|
36
|
+
## Include the Concern
|
|
37
|
+
```ruby
|
|
38
|
+
include Unidom::ArticleNumber::Concerns::AsBarcode
|
|
39
|
+
include Unidom::ArticleNumber::Concerns::AsMarked
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### As Barcode concern
|
|
43
|
+
The As Barcode concern do the following tasks for the includer automatically:
|
|
44
|
+
1. Define the Has Many macro as: ``has_many :markings, class_name: 'Unidom::ArticleNumber::Marking', as: :barcode``
|
|
45
|
+
|
|
46
|
+
### As Marked concern
|
|
47
|
+
The As Marked concern do the following tasks for the includer automatically:
|
|
48
|
+
1. Define the Has Many macro as: ``has_many :markings, class_name: 'Unidom::ArticleNumber::Marking', as: :marked``
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module Unidom::ArticleNumber::Concerns::AsBarcode
|
|
2
|
+
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
self.included do |includer|
|
|
6
|
+
|
|
7
|
+
has_many :markings, class_name: 'Unidom::ArticleNumber::Marking', as: :barcode
|
|
8
|
+
has_many :marked_products, through: :markings, source: :marked, source_type: 'Unidom::Product::Product'
|
|
9
|
+
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
@@ -8,16 +8,15 @@ class Unidom::ArticleNumber::Ean13Barcode < ActiveRecord::Base
|
|
|
8
8
|
|
|
9
9
|
self.table_name = 'unidom_ean_13_barcodes'
|
|
10
10
|
|
|
11
|
+
include Unidom::Common::Concerns::ModelExtension
|
|
12
|
+
include Unidom::ArticleNumber::Concerns::AsBarcode
|
|
13
|
+
|
|
11
14
|
validates :code, uniqueness: true, numericality: { only_integer: true }
|
|
12
15
|
validates :gs1_prefix, presence: true, length: { is: 3 }, numericality: { only_integer: true }
|
|
13
16
|
validates :company_number, presence: true, length: { is: 4 }, numericality: { only_integer: true }
|
|
14
17
|
validates :item_reference, presence: true, length: { is: 5 }, numericality: { only_integer: true }
|
|
15
18
|
validates :check_digit, presence: true, length: { is: 1 }, numericality: { only_integer: true }
|
|
16
19
|
|
|
17
|
-
has_many :markings, class_name: 'Unidom::ArticleNumber::Marking'
|
|
18
|
-
|
|
19
|
-
include Unidom::Common::Concerns::ModelExtension
|
|
20
|
-
|
|
21
20
|
def code=(code)
|
|
22
21
|
code = code.to_s
|
|
23
22
|
write_attribute :code, code
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# EAN-8 Barcode 是8位条形码。
|
|
2
2
|
# https://en.wikipedia.org/wiki/EAN-8
|
|
3
|
+
|
|
3
4
|
class Unidom::ArticleNumber::Ean8Barcode < ActiveRecord::Base
|
|
4
5
|
|
|
5
6
|
RESTRICTED_DISTRIBUTION_GS1_PREFIXES = (('020'..'029').to_a + ('040'..'049').to_a + ('200'..'299').to_a).freeze
|
|
6
7
|
|
|
7
8
|
self.table_name = 'unidom_ean_8_barcodes'
|
|
8
9
|
|
|
10
|
+
include Unidom::Common::Concerns::ModelExtension
|
|
11
|
+
include Unidom::ArticleNumber::Concerns::AsBarcode
|
|
12
|
+
|
|
9
13
|
validates :code, uniqueness: true, numericality: { only_integer: true }
|
|
10
14
|
validates :gs1_prefix, presence: true, length: { is: 3 }, numericality: { only_integer: true }
|
|
11
15
|
validates :item_reference, presence: true, length: { is: 4 }, numericality: { only_integer: true }
|
|
12
16
|
validates :check_digit, presence: true, length: { is: 1 }, numericality: { only_integer: true }
|
|
13
17
|
|
|
14
|
-
has_many :markings, class_name: 'Unidom::ArticleNumber::Marking'
|
|
15
|
-
|
|
16
|
-
include Unidom::Common::Concerns::ModelExtension
|
|
17
|
-
|
|
18
18
|
def code=(code)
|
|
19
19
|
code = code.to_s
|
|
20
20
|
write_attribute :code, code
|
|
@@ -15,9 +15,14 @@ class Unidom::ArticleNumber::Marking < ActiveRecord::Base
|
|
|
15
15
|
scope :marked_is, ->(marked) { where marked: marked }
|
|
16
16
|
|
|
17
17
|
def self.mark(barcode: nil, marked: nil, marker: nil, opened_at: Time.now)
|
|
18
|
+
self.mark! barcode: barcode, marked: marked, marker: marker, opened_at: opened_at
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.mark!(barcode: nil, marked: nil, marker: nil, opened_at: Time.now)
|
|
18
22
|
|
|
19
|
-
raise ArgumentError.new('
|
|
20
|
-
raise ArgumentError.new('
|
|
23
|
+
raise ArgumentError.new('The barcode argument is required.' ) if barcode.blank?
|
|
24
|
+
raise ArgumentError.new('The marked argument is required.' ) if marked.blank?
|
|
25
|
+
raise ArgumentError.new('The opened_at argument is required.') if opened_at.blank?
|
|
21
26
|
|
|
22
27
|
query = barcode_is(barcode).marked_is(marked).valid_at.alive
|
|
23
28
|
creation = { opened_at: opened_at }
|
|
@@ -31,4 +36,8 @@ class Unidom::ArticleNumber::Marking < ActiveRecord::Base
|
|
|
31
36
|
|
|
32
37
|
end
|
|
33
38
|
|
|
39
|
+
class << self
|
|
40
|
+
deprecate mark: :mark!, deprecator: ActiveSupport::Deprecation.new('2.0', 'unidom-article_number')
|
|
41
|
+
end
|
|
42
|
+
|
|
34
43
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: unidom-article_number
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.1'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Topbit Du
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-07-
|
|
11
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: unidom-common
|
|
@@ -40,6 +40,8 @@ files:
|
|
|
40
40
|
- app/assets/stylesheets/unidom/article_number/application.css
|
|
41
41
|
- app/controllers/unidom/article_number/application_controller.rb
|
|
42
42
|
- app/helpers/unidom/article_number/application_helper.rb
|
|
43
|
+
- app/models/unidom/article_number/concerns/as_barcode.rb
|
|
44
|
+
- app/models/unidom/article_number/concerns/as_marked.rb
|
|
43
45
|
- app/models/unidom/article_number/concerns/code128_barcode.rb
|
|
44
46
|
- app/models/unidom/article_number/ean13_barcode.rb
|
|
45
47
|
- app/models/unidom/article_number/ean8_barcode.rb
|