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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c465bce714b41f2b8ac878d9ba5df4f6d4797fd29005ce325bc4d415354a144
4
- data.tar.gz: 7d5e3cb3aefaa080899483e3031f0d93a81b2907fadac1f43c27cdc819f5a87b
3
+ metadata.gz: 771b69813b99e5d0f92e8b69acd1a6c4b30014c8b1e6b6d253d60870bcf8b719
4
+ data.tar.gz: fe2d5c4335ea33f83d42d2997725b543c3c7fcb9d8e7c9057f023be92dea9264
5
5
  SHA512:
6
- metadata.gz: ea29b421a25379cc4891d94113a49fbd73c8f4ee7dbc0bb5e3cffb6d80a0841e7bd9aca05dc1c2fb09d7091f863b9a888b8980770ede5369baf2bff993e9e331
7
- data.tar.gz: f4124579adc16d992dddfca9740e3212bb91098d06095f965ef2704a7a0a66a90ecd71cbe0d574a98cf8c1e7fe294bee1f654e4f1c1531cdfbc8cbcab000ed72
6
+ metadata.gz: 0b96260e9b0e79ca1b6add7b838adeb138d7ba0809271dd913f06759132a21145993cff3d30c55866f271160006d613b51d812417f8697d0550cd38a96f74009
7
+ data.tar.gz: e555dc61a62267987635e46bba1758134a8177d3fbf74ff769f746cc27d7b8ec175a8adc34b901d024a9cf8106c6051d4709fab09dfb81f423604f184372d259
data/Gemfile CHANGED
@@ -9,4 +9,7 @@ gem "rspec", "~> 3.0"
9
9
 
10
10
  gem "activerecord", "~> 6.0"
11
11
  gem "activestorage", "~> 6.0"
12
- gem "actiontext", "~> 6.0"
12
+ gem "actiontext", "~> 6.0"
13
+
14
+ gem "jwt"
15
+ gem "pg_ltree"
@@ -22,8 +22,8 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
22
22
  type text,
23
23
  name text,
24
24
 
25
- parent_id integer,
26
- parent_type text,
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], :parent_id
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
@@ -1,6 +1,6 @@
1
1
  class Lca::Cycle < Lca::Model
2
2
 
3
- has_many :stages, class_name: "::Lca::Stage", foreign_key: :parent_id, dependent: :destroy
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}.*")
@@ -1,4 +1,4 @@
1
1
  class Lca::Exchange < Lca::Model
2
- belongs_to :process, class_name: "::Lca::Process", foreign_key: :parent_id
3
- has_many :impacts, class_name: "::Lca::Impact", foreign_key: :parent_id, dependent: :destroy
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
@@ -1,6 +1,6 @@
1
1
  class Lca::Impact < Lca::Model
2
- belongs_to :exchange, class_name: "::Lca::Exchange", foreign_key: :parent_id
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
@@ -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
@@ -1,10 +1,9 @@
1
1
  class Lca::Process < Lca::Model
2
2
 
3
- has_many :exchanges, class_name: "::Lca::Exchange", foreign_key: :parent_id, dependent: :destroy
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
- def subprocesses
8
- ::Lca::Process.where("path ~ ?", "#{path}.*")
9
- end
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
@@ -1,6 +1,6 @@
1
1
  class Lca::Stage < Lca::Model
2
2
 
3
- belongs_to :cycle, class_name: "::Lca::Cycle", foreign_key: :parent_id
4
- has_many :processes, class_name: "::Lca::Process", foreign_key: :parent_id
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lca
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick @ Earthster