foobara 0.0.51 → 0.0.52

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: e82271074f7658b6b54239b1ba4e79c944baca14bc63af1fd48e7b5d5c418043
4
- data.tar.gz: f5f0dcd5bcd9e553dbcdbab70f4e9388ab98c99b4359aca8bfaf4d32fad89e7a
3
+ metadata.gz: 69f568d4dcdb081e50f321e36b9805621229ea6c48305cc5c15d5b352323015b
4
+ data.tar.gz: 4f4129cc01d8ef7cdb81c68f9a310641e022c5ca22ae2c394854e8053e46365c
5
5
  SHA512:
6
- metadata.gz: 33ce048fb57a1c12811756a5d1b9238b0b79587993d6f45323f65294cca6bcd46d33bc281e9021070c21e6f5852e9066927cb8e78a7f2f62c29b3e705ab95e4c
7
- data.tar.gz: 59cde8f01b6c5e74e69b78e951ea74cb4f85eecb9f41b1f7a1c79cd6f9f5ce4e492109c8b860aefcfd73f832355e0a912796d10b0e3a67d456921b06a7da62ed
6
+ metadata.gz: f8561097b379dbb98e1cc082fa6b1fb02f5d0b2cb1923c0b9360bd9e7a552cb484c305af77cde237a5fadebecdc518b75189885e01e2b2e8b7974f771ea738b9
7
+ data.tar.gz: 9568912e55c1c1593adf41143a5fd1f577d72b66e50ed69b4bf99ad4a00b3a1d048272187039904fade1a18032008547749f72fdf9b9ed8533a7fff7ffeeb998
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.52] - 2025-01-30
2
+
3
+ - Prefix and re-organize several model methods to facilitate type extension
4
+
1
5
  ## [0.0.51] - 2025-01-26
2
6
 
3
7
  - Add a Type#remove_processor_by_symbol method to help with certain situations when defining custom types
@@ -0,0 +1,39 @@
1
+ module Foobara
2
+ class DetachedEntity < Model
3
+ module Concerns
4
+ module Aliases
5
+ include Concern
6
+
7
+ module ClassMethods
8
+ def depends_on(...)
9
+ foobara_depends_on(...)
10
+ end
11
+
12
+ def deep_depends_on(...)
13
+ foobara_deep_depends_on(...)
14
+ end
15
+
16
+ def associations(...)
17
+ foobara_associations(...)
18
+ end
19
+
20
+ def deep_associations(...)
21
+ foobara_deep_associations(...)
22
+ end
23
+
24
+ def attributes_type(...)
25
+ foobara_attributes_type(...)
26
+ end
27
+
28
+ def primary_key_attribute(...)
29
+ foobara_primary_key_attribute(...)
30
+ end
31
+
32
+ def model_name(...)
33
+ foobara_model_name(...)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -11,8 +11,8 @@ module Foobara
11
11
 
12
12
  alias associations foobara_associations
13
13
 
14
- def deep_associations
15
- @deep_associations ||= begin
14
+ def foobara_deep_associations
15
+ @foobara_deep_associations ||= begin
16
16
  deep = {}
17
17
 
18
18
  associations.each_pair do |data_path, type|
@@ -29,6 +29,8 @@ module Foobara
29
29
  end
30
30
  end
31
31
 
32
+ alias deep_associations foobara_deep_associations
33
+
32
34
  # TODO: stamp this metadata out somewhere, preferably on deep_associations hash somehow
33
35
  def association(name, *association_identifiers)
34
36
  target_association_key = association_for(association_identifiers)
@@ -28,8 +28,8 @@ module Foobara
28
28
  def foobara_primary_key_attribute
29
29
  return @foobara_primary_key_attribute if @foobara_primary_key_attribute
30
30
 
31
- unless superclass == DetachedEntity
32
- @foobara_primary_key_attribute = superclass.primary_key_attribute
31
+ if superclass != DetachedEntity && superclass.respond_to?(:foobara_primary_key_attribute)
32
+ @foobara_primary_key_attribute = superclass.foobara_primary_key_attribute
33
33
  end
34
34
  end
35
35
 
@@ -2,29 +2,15 @@ module Foobara
2
2
  class DetachedEntity < Model
3
3
  module Concerns
4
4
  module Reflection
5
- class CannotConvertRecordWithoutPrimaryKeyToJsonError < StandardError; end
6
-
7
5
  include Concern
8
6
 
9
- def inspect
10
- "<#{entity_name}:#{primary_key}>"
11
- end
12
-
13
- def to_json(*_args)
14
- primary_key&.to_json || raise(
15
- CannotConvertRecordWithoutPrimaryKeyToJsonError,
16
- "Cannot call record.to_json on unless record has a primary key. " \
17
- "Consider instead calling record.attributes.to_json instead."
18
- )
19
- end
20
-
21
7
  module ClassMethods
22
- def depends_on
23
- associations.values.map(&:target_class).uniq
8
+ def foobara_depends_on
9
+ foobara_associations.values.map(&:target_class).uniq
24
10
  end
25
11
 
26
- def deep_depends_on
27
- types = deep_associations.sort_by do |path, _type|
12
+ def foobara_deep_depends_on
13
+ types = foobara_deep_associations.sort_by do |path, _type|
28
14
  [DataPath.new(path).path.size, path]
29
15
  end.map(&:last)
30
16
 
@@ -32,29 +18,32 @@ module Foobara
32
18
  end
33
19
 
34
20
  def foobara_manifest(to_include: Set.new)
35
- associations = self.associations.map do |(path, type)|
21
+ associations = foobara_associations.map do |(path, type)|
36
22
  entity_class = type.target_class
37
- entity_name = entity_class.full_entity_name
23
+ entity_name = entity_class.foobara_type.scoped_full_name
38
24
 
39
25
  [path, entity_name]
40
26
  end.sort.to_h
41
27
 
42
- deep_associations = self.deep_associations.map do |(path, type)|
28
+ deep_associations = foobara_deep_associations.map do |(path, type)|
43
29
  entity_class = type.target_class
44
- entity_name = entity_class.full_entity_name
30
+ entity_name = entity_class.foobara_type.scoped_full_name
45
31
 
46
32
  [path, entity_name]
47
33
  end.sort.to_h
48
34
 
49
- super.merge(
35
+ base_manifest = superclass.respond_to?(:foobara_manifest) ? super : {}
36
+
37
+ base_manifest.merge(
50
38
  Util.remove_blank(
51
- depends_on: depends_on.map(&:full_entity_name),
52
- deep_depends_on: deep_depends_on.map(&:full_entity_name),
39
+ depends_on: foobara_depends_on.map(&:full_entity_name),
40
+ deep_depends_on: foobara_deep_depends_on.map(&:full_entity_name),
53
41
  associations:,
54
42
  deep_associations:,
55
- entity_name:,
56
- primary_key_attribute:,
57
- primary_key_type: attributes_type.declaration_data[:element_type_declarations][primary_key_attribute]
43
+ entity_name: foobara_model_name,
44
+ primary_key_attribute: foobara_primary_key_attribute,
45
+ primary_key_type:
46
+ foobara_attributes_type.declaration_data[:element_type_declarations][foobara_primary_key_attribute]
58
47
  )
59
48
  )
60
49
  end
@@ -0,0 +1,23 @@
1
+ module Foobara
2
+ class DetachedEntity < Model
3
+ module Concerns
4
+ module Serialize
5
+ class CannotConvertRecordWithoutPrimaryKeyToJsonError < StandardError; end
6
+
7
+ include Concern
8
+
9
+ def inspect
10
+ "<#{entity_name}:#{primary_key}>"
11
+ end
12
+
13
+ def to_json(*_args)
14
+ primary_key&.to_json || raise(
15
+ CannotConvertRecordWithoutPrimaryKeyToJsonError,
16
+ "Cannot call record.to_json on unless record has a primary key. " \
17
+ "Consider instead calling record.attributes.to_json instead."
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -5,6 +5,8 @@ module Foobara
5
5
  include Concerns::PrimaryKey
6
6
  include Concerns::Reflection
7
7
  include Concerns::Types
8
+ include Concerns::Aliases
9
+ include Concerns::Serialize
8
10
 
9
11
  class << self
10
12
  def allowed_subclass_opts
@@ -0,0 +1,15 @@
1
+ module Foobara
2
+ class Model
3
+ module Concerns
4
+ module Aliases
5
+ include Concern
6
+
7
+ module ClassMethods
8
+ def model_name(...)
9
+ foobara_model_name(...)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -7,12 +7,12 @@ module Foobara
7
7
  module ClassMethods
8
8
  def foobara_manifest(to_include: Set.new)
9
9
  Util.remove_blank(
10
- attributes_type: attributes_type.declaration_data,
11
- organization_name:,
12
- domain_name:,
13
- model_name:,
14
- model_base_class: model_type.declaration_data[:model_base_class],
15
- model_class: model_type.declaration_data[:model_class]
10
+ attributes_type: foobara_attributes_type.declaration_data,
11
+ organization_name: foobara_type.foobara_domain.foobara_organization_name,
12
+ domain_name: foobara_type.foobara_domain.foobara_domain_name,
13
+ model_name: foobara_model_name,
14
+ model_base_class: foobara_type.declaration_data[:model_base_class],
15
+ model_class: foobara_type.declaration_data[:model_class]
16
16
  )
17
17
  end
18
18
  end
@@ -80,6 +80,10 @@ module Foobara
80
80
  end
81
81
  end
82
82
 
83
+ def foobara_type
84
+ model_type
85
+ end
86
+
83
87
  def type_declaration(attributes_declaration)
84
88
  if name.start_with?(closest_namespace_module.name)
85
89
  model_module_name = closest_namespace_module.name
@@ -8,6 +8,7 @@ module Foobara
8
8
 
9
9
  include Concerns::Types
10
10
  include Concerns::Reflection
11
+ include Concerns::Aliases
11
12
 
12
13
  class << self
13
14
  attr_accessor :is_abstract
@@ -84,8 +85,8 @@ module Foobara
84
85
  end
85
86
  end
86
87
 
87
- def model_name
88
- model_type&.scoped_name || Util.non_full_name(self)
88
+ def foobara_model_name
89
+ foobara_type&.scoped_name || Util.non_full_name(self)
89
90
  rescue Foobara::Scoped::NoScopedPathSetError
90
91
  # :nocov:
91
92
  Util.non_full_name(self)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.51
4
+ version: 0.0.52
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-27 00:00:00.000000000 Z
10
+ date: 2025-01-30 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal
@@ -186,10 +186,12 @@ files:
186
186
  - projects/delegate/lib/foobara/delegate.rb
187
187
  - projects/delegate/src/extensions/module.rb
188
188
  - projects/detached_entity/lib/foobara/detached_entity.rb
189
+ - projects/detached_entity/src/concerns/aliases.rb
189
190
  - projects/detached_entity/src/concerns/associations.rb
190
191
  - projects/detached_entity/src/concerns/equality.rb
191
192
  - projects/detached_entity/src/concerns/primary_key.rb
192
193
  - projects/detached_entity/src/concerns/reflection.rb
194
+ - projects/detached_entity/src/concerns/serialize.rb
193
195
  - projects/detached_entity/src/concerns/types.rb
194
196
  - projects/detached_entity/src/detached_entity.rb
195
197
  - projects/detached_entity/src/extensions/builtin_types/detached_entity.rb
@@ -270,6 +272,7 @@ files:
270
272
  - projects/manifest/src/foobara/manifest/type.rb
271
273
  - projects/manifest/src/foobara/manifest/type_declaration.rb
272
274
  - projects/model/lib/foobara/model.rb
275
+ - projects/model/src/concerns/aliases.rb
273
276
  - projects/model/src/concerns/reflection.rb
274
277
  - projects/model/src/concerns/types.rb
275
278
  - projects/model/src/extensions/builtin_types/model/casters/hash.rb
@@ -438,7 +441,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
438
441
  - !ruby/object:Gem::Version
439
442
  version: '0'
440
443
  requirements: []
441
- rubygems_version: 3.6.2
444
+ rubygems_version: 3.6.3
442
445
  specification_version: 4
443
446
  summary: A command-centric and discoverable software framework with a focus on domain
444
447
  concepts and abstracting away integration code