activerecord-cti 1.0.0 → 1.0.2

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: 836881d73a9673eb8de7d7090a2b00fcf0488a4e6a98b7cc17c4d4e8653eccd3
4
- data.tar.gz: 8412e160c4687ea28ec62cf34ee4b7d82d5c174a294f9fac771a326537bb4bb9
3
+ metadata.gz: b73040f6da6dad822aa1840b28f2cfeb15db794c8714941301ada52f44fffbf5
4
+ data.tar.gz: 475064ad401435250f3cd6812b86fafaadad413c812e3c860ca61a45008726ff
5
5
  SHA512:
6
- metadata.gz: b94a30910639e51487ee22b50ef7d66459ba062db0a43d85e2bd91b2077e928dffe3c65c37dc5e55f244d0b987d2ded42fce27056ed935a13d072c49e2831495
7
- data.tar.gz: feb4910a8fd049b311424495f7423b408d49067e8ce3e24b666930c35cec80ce33afc5df16b6fc02db87b9dc7a97b25bde86e9a3d77afca589b01521da548973
6
+ metadata.gz: bf497e50f0f0c3bc5832b88bbcf2abab46b9757789b6e2f884e36716f87c32d1d6ccb8dd3f0a24cc96edf056d6901a75d8e9acc4764a7ab56d1851a96387c9ba
7
+ data.tar.gz: ee03298b1bf54dc60298f8fdce58c5e46b41fb3379eb6fcecbf2aab40c9396cce71076ea046651e749cebab93bfbad0ea5044fb727bbdf6c3ff217e890b03938
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ActiveRecord::Cti
2
- ActiveRecord-Cti is a library implemented [Class Table Inheritance](https://martinfowler.com/eaaCatalog/classTableInheritance.html) on ActiveRecord.
2
+ ActiveRecord-Cti is a library implemented [Class Table Inheritance](https://martinfowler.com/eaaCatalog/classTableInheritance.html) on Ruby on Rails.
3
3
  Class Table Inheritance (CTI) is useful under the circumstances that an ActiveRecord object is in multiple positions or has multiple roles, and you want to describe it's structure on the database.
4
- For Example, one person may be a player and a coach in a soccer team.
4
+ For example, one person may be a player and a coach in a soccer team.
5
5
 
6
6
  ## Why use activerecord-cti ?
7
7
  In ActiveRecord, Single Table Inheritance(STI) is implemented as a method of how to express inheritance model on database. Class Table Inheritance (CTI) has more powerful and flexible expressiveness for inheritance model on database than it of STI.
@@ -13,13 +13,13 @@ For Example, Suppose you want to describe the following class structure on datab
13
13
  But STI has a disadvantage that it is not possible to represent one record as an object of two different models at the same time.
14
14
 
15
15
  #### people talbe (STI)
16
- | id | type | name | birth_year | position_name | licence_name |
16
+ | id | type | name | birth_year | position_name | license_name |
17
17
  |----|------|-----------|------------|-----------------|---------------|
18
18
  | 1 |Player| Ryan Giggs| 1973 | midfielder | |
19
19
  | 2 |Coach | Ryan Giggs| 1973 | | UEFA Pro |
20
20
 
21
21
  As mentiond above, for expressing two `Person`'s subclasses objects, which are `Player` and `Coach`, you have to insert two records into people table in STI.
22
- It is cursed that the contents of `name` and `birth_year` columns are duplicated and `position_name` and `licence_name` columns are sparse.
22
+ It is cursed that the contents of `name` and `birth_year` columns are duplicated and `position_name` and `license_name` columns are sparse.
23
23
 
24
24
  CTI can solve these problems by using multiple related tables like shown below, literally for class table inheritance.
25
25
 
@@ -1,3 +1,5 @@
1
+ require 'active_support/concern'
2
+
1
3
  module ActiveRecord
2
4
  module Cti
3
5
  module BaseClass
@@ -1,6 +1,8 @@
1
1
  module Activerecord
2
2
  module Cti
3
- class Railtie < ::Rails::Railtie
3
+ if defined?(Rails)
4
+ class Railtie < ::Rails::Railtie
5
+ end
4
6
  end
5
7
  end
6
8
  end
@@ -7,7 +7,8 @@ module ActiveRecord
7
7
  default_scope { joins("INNER JOIN #{superclass_table_name} ON #{table_name}.#{foreign_key_name} = #{superclass_table_name}.id").select(default_select_columns) }
8
8
 
9
9
  # Define dinamically to_* methods, which convert self to other subclass has same CTI superclass.
10
- Pathname.glob("#{Rails.root}/app/models/*").collect do
10
+ models_dir_path = defined?(Rails) ? "#{Rails.root}/app/models" : ENV['APP_MODELS_DIR_PATH']
11
+ Pathname.glob("#{models_dir_path}/*").collect do
11
12
  |path| path.basename.to_s.split('.').first.classify.safe_constantize
12
13
  end.compact.delete_if do |model|
13
14
  !model.superclass.include?(ActiveRecord::Cti::BaseClass) or model == self
@@ -58,14 +59,14 @@ module ActiveRecord
58
59
  end
59
60
 
60
61
  def find_by(*args)
61
- unless subclass_column_names.include?(args.first.keys.first)
62
+ unless subclass_column_names.include?(args.first.keys.first.to_s)
62
63
  args = [{"#{superclass_table_name}.#{args.first.keys.first.to_s}": args.first.values.first}]
63
64
  end
64
65
  super
65
66
  end
66
67
 
67
68
  def where(opts = :chain, *rest)
68
- unless subclass_column_names.include?(opts.keys.first)
69
+ unless subclass_column_names.include?(opts.keys.first.to_s)
69
70
  opts = {"#{superclass_table_name}.#{opts.keys.first.to_s}": opts.values.first}
70
71
  end
71
72
  super
@@ -1,5 +1,5 @@
1
1
  module Activerecord
2
2
  module Cti
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,35 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-cti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - khata
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-20 00:00:00.000000000 Z
11
+ date: 2023-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 6.0.2
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 6.0.2.1
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: 6.0.2
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 6.0.2.1
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: sqlite3
35
15
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +25,7 @@ dependencies:
45
25
  - !ruby/object:Gem::Version
46
26
  version: '0'
47
27
  description: ActiveRecord-Cti is a library implemented Class Table Inheritance on
48
- ActiveRecord. Class Table Inheritance (CTI) is useful under the circumstances that
28
+ Ruby on Rails. Class Table Inheritance (CTI) is useful under the circumstances that
49
29
  an ActiveRecord object is in multiple positions or has multiple roles, and you want
50
30
  to describe it's structure on the database. For Example, one person may be a player
51
31
  and a coach in a soccer team.
@@ -68,7 +48,7 @@ homepage: https://bs.tokushima-inc.jp/
68
48
  licenses:
69
49
  - MIT
70
50
  metadata: {}
71
- post_install_message:
51
+ post_install_message:
72
52
  rdoc_options: []
73
53
  require_paths:
74
54
  - lib
@@ -83,8 +63,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
63
  - !ruby/object:Gem::Version
84
64
  version: '0'
85
65
  requirements: []
86
- rubygems_version: 3.0.3
87
- signing_key:
66
+ rubygems_version: 3.2.15
67
+ signing_key:
88
68
  specification_version: 4
89
- summary: ActiveRecord-Cti is a library implemented Class Table Inheritance on ActiveRecord.
69
+ summary: ActiveRecord-Cti is a library implemented Class Table Inheritance on Ruby
70
+ on Rails.
90
71
  test_files: []