lca 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -1
- data/lib/generators/lca/templates/migration.rb.tt +3 -3
- data/lib/lca/models/cycle.rb +1 -1
- data/lib/lca/models/exchange.rb +2 -2
- data/lib/lca/models/impact.rb +2 -2
- data/lib/lca/models/model.rb +7 -3
- data/lib/lca/models/process.rb +4 -5
- data/lib/lca/models/stage.rb +2 -2
- data/lib/lca/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 771b69813b99e5d0f92e8b69acd1a6c4b30014c8b1e6b6d253d60870bcf8b719
|
4
|
+
data.tar.gz: fe2d5c4335ea33f83d42d2997725b543c3c7fcb9d8e7c9057f023be92dea9264
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b96260e9b0e79ca1b6add7b838adeb138d7ba0809271dd913f06759132a21145993cff3d30c55866f271160006d613b51d812417f8697d0550cd38a96f74009
|
7
|
+
data.tar.gz: e555dc61a62267987635e46bba1758134a8177d3fbf74ff769f746cc27d7b8ec175a8adc34b901d024a9cf8106c6051d4709fab09dfb81f423604f184372d259
|
data/Gemfile
CHANGED
@@ -22,8 +22,8 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
|
|
22
22
|
type text,
|
23
23
|
name text,
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
parent_entity_id integer,
|
26
|
+
parent_entity_type text,
|
27
27
|
|
28
28
|
path ltree,
|
29
29
|
path_slug text,
|
@@ -44,7 +44,7 @@ SQL
|
|
44
44
|
add_index LCA_OPTIONS[:table_name], :id
|
45
45
|
add_index LCA_OPTIONS[:table_name], :owner_id
|
46
46
|
add_index LCA_OPTIONS[:table_name], :type
|
47
|
-
add_index LCA_OPTIONS[:table_name], :
|
47
|
+
add_index LCA_OPTIONS[:table_name], :parent_entity_id
|
48
48
|
|
49
49
|
# next two indexes unfortunately can't be unique since a cycle can appear several times under an owner
|
50
50
|
add_index LCA_OPTIONS[:table_name], :path, using: :gist
|
data/lib/lca/models/cycle.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Lca::Cycle < Lca::Model
|
2
2
|
|
3
|
-
has_many :stages, class_name: "::Lca::Stage", foreign_key: :
|
3
|
+
has_many :stages, class_name: "::Lca::Stage", foreign_key: :parent_entity_id, dependent: :destroy
|
4
4
|
|
5
5
|
def subcycles
|
6
6
|
::Lca::Cycle.match_path("#{path}.*")
|
data/lib/lca/models/exchange.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
class Lca::Exchange < Lca::Model
|
2
|
-
belongs_to :process, class_name: "::Lca::Process", foreign_key: :
|
3
|
-
has_many :impacts, class_name: "::Lca::Impact", foreign_key: :
|
2
|
+
belongs_to :process, class_name: "::Lca::Process", foreign_key: :parent_entity_id, required: true
|
3
|
+
has_many :impacts, class_name: "::Lca::Impact", foreign_key: :parent_entity_id, dependent: :destroy
|
4
4
|
end
|
data/lib/lca/models/impact.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Lca::Impact < Lca::Model
|
2
|
-
belongs_to :exchange, class_name: "::Lca::Exchange", foreign_key: :
|
3
|
-
|
2
|
+
belongs_to :exchange, class_name: "::Lca::Exchange", foreign_key: :parent_entity_id, required: true
|
3
|
+
|
4
4
|
validates_presence_of :impact_amount
|
5
5
|
validates_presence_of :impact_amount_unit, allow_blank: false
|
6
6
|
validates_presence_of :impact_factor
|
data/lib/lca/models/model.rb
CHANGED
@@ -9,7 +9,7 @@ class Lca::Model < ActiveRecord::Base
|
|
9
9
|
return "lca_models"
|
10
10
|
end
|
11
11
|
|
12
|
-
belongs_to :owner, polymorphic: :true
|
12
|
+
belongs_to :owner, polymorphic: :true, required: true
|
13
13
|
|
14
14
|
scope :match_path, -> (some_path) { where("path ~ ?", "#{some_path}") }
|
15
15
|
|
@@ -21,8 +21,8 @@ class Lca::Model < ActiveRecord::Base
|
|
21
21
|
|
22
22
|
before_validation :set_defaults
|
23
23
|
def set_defaults
|
24
|
-
self.path ||= name.parameterize.gsub("-", ".")
|
25
|
-
self.path_slug = path.parameterize
|
24
|
+
self.path ||= name.parameterize.gsub("-", ".") if name
|
25
|
+
self.path_slug = path.parameterize if path
|
26
26
|
end
|
27
27
|
|
28
28
|
|
@@ -57,6 +57,10 @@ class Lca::Model < ActiveRecord::Base
|
|
57
57
|
class_name
|
58
58
|
end
|
59
59
|
|
60
|
+
model_class.define_singleton_method(:sti_name) do
|
61
|
+
original_class_name
|
62
|
+
end
|
63
|
+
|
60
64
|
# override the STI name lmfao
|
61
65
|
model_class.define_singleton_method(:find_sti_class) do |p|
|
62
66
|
original_class_name.constantize
|
data/lib/lca/models/process.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
class Lca::Process < Lca::Model
|
2
2
|
|
3
|
-
has_many :exchanges, class_name: "::Lca::Exchange", foreign_key: :
|
3
|
+
has_many :exchanges, class_name: "::Lca::Exchange", foreign_key: :parent_entity_id, dependent: :destroy
|
4
4
|
has_many :impacts, through: :exchanges
|
5
|
-
belongs_to :stage, class_name: "::Lca::Stage", foreign_key: :parent_id
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
has_many :subprocesses, class_name: "::Lca::Process", foreign_key: :parent_entity_id, dependent: :destroy, as: :parent_entity
|
7
|
+
belongs_to :parent_entity, polymorphic: true, required: true
|
8
|
+
|
10
9
|
end
|
data/lib/lca/models/stage.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Lca::Stage < Lca::Model
|
2
2
|
|
3
|
-
belongs_to :cycle, class_name: "::Lca::Cycle", foreign_key: :
|
4
|
-
has_many :processes, class_name: "::Lca::Process", foreign_key: :
|
3
|
+
belongs_to :cycle, class_name: "::Lca::Cycle", foreign_key: :parent_entity_id, required: true
|
4
|
+
has_many :processes, class_name: "::Lca::Process", foreign_key: :parent_entity_id
|
5
5
|
|
6
6
|
end
|
data/lib/lca/version.rb
CHANGED