dscf-marketplace 0.1.2 → 0.1.3
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/app/models/dscf/marketplace/unit.rb +3 -3
- data/app/models/dscf/marketplace/unit_conversion.rb +33 -0
- data/db/migrate/20250827185656_create_dscf_marketplace_unit_conversions.rb +23 -0
- data/lib/dscf/marketplace/version.rb +1 -1
- data/spec/factories/dscf/marketplace/unit_conversions.rb +8 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 796eeeaf3921a9ddb0e478285af2b644a972cb51a53231a39e7062e7c4b53f0a
|
4
|
+
data.tar.gz: af123ae47644fd07cca78b7e3b4907ef79d530cf96dff069338499ebf908cd0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6aa7f04ccb27eb52e027c68a72c429cfdf793d9c7dfde195851b868e6a69296e6328000eed13fd12075dd18ef76f164f6d7a8deee69a1dc31869f809c30da79
|
7
|
+
data.tar.gz: 9a4653a2bbd5b67779a5180ea2dc660971e50485ed6224d86f7904079bdc1302bd6c26bb2c8006761c22f43b9e0f5e335c15db9bbfff8ed6098b83f51a5b9fdc
|
@@ -30,10 +30,10 @@ module Dscf
|
|
30
30
|
|
31
31
|
def convertible_to?(other_unit)
|
32
32
|
return false if other_unit.nil?
|
33
|
+
return true if id == other_unit.id
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
false
|
35
|
+
unit_conversions.exists?(to_unit: other_unit) ||
|
36
|
+
other_unit.unit_conversions.exists?(to_unit: self)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Dscf
|
2
|
+
module Marketplace
|
3
|
+
class UnitConversion < ApplicationRecord
|
4
|
+
belongs_to :from_unit, class_name: "Dscf::Marketplace::Unit"
|
5
|
+
belongs_to :to_unit, class_name: "Dscf::Marketplace::Unit"
|
6
|
+
|
7
|
+
validates :from_unit_id, presence: true
|
8
|
+
validates :to_unit_id, presence: true
|
9
|
+
validates :conversion_factor, presence: true, numericality: {greater_than: 0}
|
10
|
+
validates :notes, length: {maximum: 500}, allow_blank: true
|
11
|
+
|
12
|
+
validate :units_must_be_different
|
13
|
+
|
14
|
+
def units_must_be_different
|
15
|
+
return unless from_unit_id && to_unit_id
|
16
|
+
|
17
|
+
return unless from_unit_id == to_unit_id
|
18
|
+
|
19
|
+
errors.add(:to_unit_id, "must be different from from_unit")
|
20
|
+
end
|
21
|
+
|
22
|
+
def reverse_conversion_factor
|
23
|
+
return nil unless conversion_factor && conversion_factor != 0
|
24
|
+
|
25
|
+
1.0 / conversion_factor
|
26
|
+
end
|
27
|
+
|
28
|
+
def description
|
29
|
+
"#{from_unit&.display_name} → #{to_unit&.display_name} (×#{conversion_factor})"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CreateDscfMarketplaceUnitConversions < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :dscf_marketplace_unit_conversions do |t|
|
4
|
+
t.references :from_unit,
|
5
|
+
index: {name: "from_unit_on_dm_uc_indx"},
|
6
|
+
null: false,
|
7
|
+
foreign_key: {to_table: :dscf_marketplace_units}
|
8
|
+
t.references :to_unit,
|
9
|
+
index: {name: "to_unit_on_dm_uc_indx"},
|
10
|
+
null: false,
|
11
|
+
foreign_key: {to_table: :dscf_marketplace_units}
|
12
|
+
t.decimal :conversion_factor, precision: 15, scale: 6, null: false
|
13
|
+
t.string :notes, limit: 500
|
14
|
+
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
|
18
|
+
add_index :dscf_marketplace_unit_conversions,
|
19
|
+
%i[from_unit_id to_unit_id],
|
20
|
+
unique: true,
|
21
|
+
name: "unique_unit_conversion_indx"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :dscf_marketplace_unit_conversion, class: "Dscf::Marketplace::UnitConversion" do
|
3
|
+
from_unit { create(:dscf_marketplace_unit) }
|
4
|
+
to_unit { create(:dscf_marketplace_unit) }
|
5
|
+
conversion_factor { 1.5 }
|
6
|
+
notes { "Conversion factor description" }
|
7
|
+
end
|
8
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dscf-marketplace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asrat
|
@@ -423,15 +423,18 @@ files:
|
|
423
423
|
- app/models/dscf/marketplace/application_record.rb
|
424
424
|
- app/models/dscf/marketplace/category.rb
|
425
425
|
- app/models/dscf/marketplace/unit.rb
|
426
|
+
- app/models/dscf/marketplace/unit_conversion.rb
|
426
427
|
- config/routes.rb
|
427
428
|
- db/migrate/20250827172043_create_dscf_marketplace_categories.rb
|
428
429
|
- db/migrate/20250827173526_update_dscf_marketplace_categories_indexes.rb
|
429
430
|
- db/migrate/20250827182550_create_dscf_marketplace_units.rb
|
431
|
+
- db/migrate/20250827185656_create_dscf_marketplace_unit_conversions.rb
|
430
432
|
- lib/dscf/marketplace.rb
|
431
433
|
- lib/dscf/marketplace/engine.rb
|
432
434
|
- lib/dscf/marketplace/version.rb
|
433
435
|
- lib/tasks/dscf/marketplace_tasks.rake
|
434
436
|
- spec/factories/dscf/marketplace/categories.rb
|
437
|
+
- spec/factories/dscf/marketplace/unit_conversions.rb
|
435
438
|
- spec/factories/dscf/marketplace/units.rb
|
436
439
|
homepage: https://mksaddis.com/
|
437
440
|
licenses:
|
@@ -446,7 +449,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
446
449
|
requirements:
|
447
450
|
- - ">="
|
448
451
|
- !ruby/object:Gem::Version
|
449
|
-
version: '3.
|
452
|
+
version: '3.4'
|
450
453
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
451
454
|
requirements:
|
452
455
|
- - ">="
|