granite 0.14.2 → 0.15.0

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: 9d4056c068ce20c44a4951e8f2c6c52be5d37913900c79a32041627c08bc09d9
4
- data.tar.gz: 00127702e26bd46b17778e6ead007acce5b59cfbfd1a3b01d315c8286b6b6d36
3
+ metadata.gz: 2cf5813f23b963898bbdd4f55d35b2f0699428c657413ee6f18d56713ffcf659
4
+ data.tar.gz: 48a04a7a60bf1819222728acf33c8bf0a73149d9b9d83b2ea04bc70a2182ec04
5
5
  SHA512:
6
- metadata.gz: 611de3a2edf7e5b7e42d2da1b06f35cef0a49c3ff7712c3bffe57a4f0deecd7e3454216dd13617914d211825a34764b223ad8b780537a9d4d0122c7aa0e0e429
7
- data.tar.gz: 5273870b5a1a2c0d93deef1a21d3c8f3d40bda27e19588199a6301544d7d454df50243dbd4bedf766988ddf37502e177c727f998d5fabbbfeef4761bd395d31d
6
+ metadata.gz: b182f94aa37d25756606fe9384a5ea98963279f8a58f84a66a7660fd21a3076b46f6965d56e26d5bc75357431f9bec2dfabb639bd198b0d00529d2567dd21628
7
+ data.tar.gz: 814dbec1866a2845d869489d82051feb017e4c850460fef1af69f13d31cf6c40fb66dbddec52529e84dfd292acce8bf73bb4479f9f8e2fca42c586c9dd12b2a2
@@ -66,7 +66,7 @@ module Granite
66
66
 
67
67
  self.subject = args.first unless args.empty?
68
68
  fail SubjectNotFoundError, self.class unless subject
69
- rescue ActiveData::AssociationTypeMismatch
69
+ rescue Granite::Form::AssociationTypeMismatch
70
70
  raise SubjectTypeMismatchError.new(self.class, args.first.class.name, reflection.klass)
71
71
  end
72
72
 
@@ -75,7 +75,7 @@ module Granite
75
75
 
76
76
  def log_errors(errors)
77
77
  errors.each do |error|
78
- ActiveData.config.logger.error "Unhandled error in callback: #{error.inspect}\n#{error.backtrace.join("\n")}"
78
+ Granite::Form.config.logger.error "Unhandled error in callback: #{error.inspect}\n#{error.backtrace.join("\n")}"
79
79
  end
80
80
  end
81
81
  end
@@ -1,4 +1,4 @@
1
- require 'active_data'
1
+ require 'granite/form'
2
2
  require 'active_record/errors'
3
3
  require 'active_record/validations'
4
4
  require 'active_support/callbacks'
@@ -27,7 +27,7 @@ module Granite
27
27
  end
28
28
 
29
29
  # We are using a lot of stacked additional logic for `assign_attributes`
30
- # At least, represented and nested attributes modules in ActiveData
30
+ # At least, represented and nested attributes modules in Granite::Form
31
31
  # are having such a method redefiniions. Both are prepended to the
32
32
  # Granite action, so we have to prepend our patch as well in order
33
33
  # to put it above all other, so it will handle the attributes first.
@@ -55,7 +55,7 @@ module Granite
55
55
  merge_errors(e.record.errors)
56
56
  end
57
57
 
58
- handle_exception ActiveData::ValidationError do |e|
58
+ handle_exception Granite::Form::ValidationError do |e|
59
59
  merge_errors(e.model.errors)
60
60
  end
61
61
 
data/lib/granite/base.rb CHANGED
@@ -1,24 +1,24 @@
1
- require 'active_data/model'
2
- require 'active_data/model/primary'
3
- require 'active_data/model/lifecycle'
4
- require 'active_data/model/associations'
1
+ require 'granite/form/model'
2
+ require 'granite/form/model/primary'
3
+ require 'granite/form/model/lifecycle'
4
+ require 'granite/form/model/associations'
5
5
 
6
6
  require 'granite/translations'
7
7
  require 'granite/represents'
8
8
  require 'granite/assign_data'
9
9
 
10
10
  module Granite
11
- # Base included in Granite::Action, but also used by ActiveData when building data objects (e.g. when using
11
+ # Base included in Granite::Action, but also used by Granite::Form when building data objects (e.g. when using
12
12
  # embeds_many)
13
13
  module Base
14
14
  extend ActiveSupport::Concern
15
15
 
16
16
  include ActiveSupport::Callbacks
17
- include ActiveData::Model
18
- include ActiveData::Model::Representation
19
- include ActiveData::Model::Dirty
20
- include ActiveData::Model::Associations
21
- include ActiveData::Model::Primary
17
+ include Granite::Form::Model
18
+ include Granite::Form::Model::Representation
19
+ include Granite::Form::Model::Dirty
20
+ include Granite::Form::Model::Associations
21
+ include Granite::Form::Model::Primary
22
22
  include ActiveModel::Validations::Callbacks
23
23
 
24
24
  include Granite::Util
@@ -1,10 +1,9 @@
1
1
  module Granite
2
2
  module Represents
3
- class Attribute < ActiveData::Model::Attributes::Attribute
3
+ class Attribute < Granite::Form::Model::Attributes::Attribute
4
4
  types = {}
5
5
  types[ActiveRecord::Enum::EnumType] = String if defined?(ActiveRecord)
6
6
  TYPES = types.freeze
7
-
8
7
  delegate :writer, :reader, :reader_before_type_cast, to: :reflection
9
8
 
10
9
  def initialize(*_args)
@@ -27,13 +26,13 @@ module Granite
27
26
  def type
28
27
  return reflection.options[:type] if reflection.options[:type].present?
29
28
 
30
- active_data_type || type_from_type_for_attribute || super
29
+ granite_form_type || type_from_type_for_attribute || super
31
30
  end
32
31
 
33
32
  def typecaster
34
33
  @typecaster ||= begin
35
34
  type_class = type.instance_of?(Class) ? type : type.class
36
- @typecaster = ActiveData.typecaster(type_class.ancestors.grep(Class))
35
+ @typecaster = Granite::Form.typecaster(type_class.ancestors.grep(Class))
37
36
  end
38
37
  end
39
38
 
@@ -67,26 +66,26 @@ module Granite
67
66
  end
68
67
  end
69
68
 
70
- def active_data_type
71
- return nil unless reference.is_a?(ActiveData::Model)
69
+ def granite_form_type
70
+ return nil unless reference.is_a?(Granite::Form::Model)
72
71
 
73
72
  reference_attribute = reference.attribute(name)
74
73
 
75
74
  return nil if reference_attribute.nil?
76
75
 
77
76
  return Granite::Action::Types::Collection.new(reference_attribute.type) if [
78
- ActiveData::Model::Attributes::ReferenceMany,
79
- ActiveData::Model::Attributes::Collection,
80
- ActiveData::Model::Attributes::Dictionary
77
+ Granite::Form::Model::Attributes::ReferenceMany,
78
+ Granite::Form::Model::Attributes::Collection,
79
+ Granite::Form::Model::Attributes::Dictionary
81
80
  ].any? { |klass| reference_attribute.is_a? klass }
82
81
 
83
- reference_attribute.type # TODO: create `type_for_attribute` method inside of ActiveData
82
+ reference_attribute.type # TODO: create `type_for_attribute` method inside of Granite::Form
84
83
  end
85
84
 
86
85
  def type_from_type_for_attribute
87
86
  return nil unless reference.respond_to?(:type_for_attribute)
88
87
 
89
- attribute_type = reference.type_for_attribute(name.to_s)
88
+ attribute_type = reference.type_for_attribute(attribute_name.to_s)
90
89
 
91
90
  return TYPES[attribute_type.class] if TYPES.key?(attribute_type.class)
92
91
  return Granite::Action::Types::Collection.new(convert_type_to_value_class(attribute_type.subtype)) if attribute_type.respond_to?(:subtype)
@@ -94,10 +93,16 @@ module Granite
94
93
  convert_type_to_value_class(attribute_type)
95
94
  end
96
95
 
96
+ def attribute_name
97
+ return name if ActiveModel.version >= Gem::Version.new('6.1.0')
98
+
99
+ reference.class.attribute_aliases[name.to_s] || name
100
+ end
101
+
97
102
  def convert_type_to_value_class(attribute_type)
98
103
  return attribute_type.value_class if attribute_type.respond_to?(:value_class)
99
104
 
100
- ActiveData::Model::Associations::PersistenceAdapters::ActiveRecord::TYPES[attribute_type.type&.to_sym]
105
+ Granite::Form::Model::Associations::PersistenceAdapters::ActiveRecord::TYPES[attribute_type.type&.to_sym]
101
106
  end
102
107
  end
103
108
  end
@@ -2,7 +2,7 @@ require 'granite/represents/attribute'
2
2
 
3
3
  module Granite
4
4
  module Represents
5
- class Reflection < ActiveData::Model::Attributes::Reflections::Represents
5
+ class Reflection < Granite::Form::Model::Attributes::Reflections::Represents
6
6
  class << self
7
7
  def build(target, generated_methods, name, *args, &block)
8
8
  options = args.last
@@ -1,7 +1,7 @@
1
- require 'active_data'
1
+ require 'granite/form'
2
2
 
3
- ActiveData.typecaster('Granite::Action::Types::Collection') do |value, attribute|
4
- typecaster = ActiveData.typecaster(attribute.type.subtype)
3
+ Granite::Form.typecaster('Granite::Action::Types::Collection') do |value, attribute|
4
+ typecaster = Granite::Form.typecaster(attribute.type.subtype)
5
5
  if value.respond_to? :transform_values
6
6
  value.transform_values { |v| typecaster.call(v, attribute) }
7
7
  elsif value.respond_to?(:map)
@@ -1,3 +1,3 @@
1
1
  module Granite
2
- VERSION = '0.14.2'.freeze
2
+ VERSION = '0.15.0'.freeze
3
3
  end
data/lib/granite.rb CHANGED
@@ -28,4 +28,4 @@ require 'granite/routing'
28
28
  require 'granite/typecasters'
29
29
  require 'granite/rails' if defined?(::Rails)
30
30
 
31
- ActiveData.base_concern = Granite::Base
31
+ Granite::Form.base_concern = Granite::Base
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: granite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.2
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toptal Engineering
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-13 00:00:00.000000000 Z
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -31,19 +31,19 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
- name: active_data
34
+ name: granite-form
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 1.2.0
39
+ version: '0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - "~>"
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 1.2.0
46
+ version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activesupport
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -316,8 +316,8 @@ dependencies:
316
316
  - - "~>"
317
317
  - !ruby/object:Gem::Version
318
318
  version: '0.15'
319
- description:
320
- email:
319
+ description:
320
+ email:
321
321
  executables: []
322
322
  extensions: []
323
323
  extra_rdoc_files: []
@@ -400,7 +400,7 @@ homepage: https://github.com/toptal/granite
400
400
  licenses:
401
401
  - MIT
402
402
  metadata: {}
403
- post_install_message:
403
+ post_install_message:
404
404
  rdoc_options: []
405
405
  require_paths:
406
406
  - lib
@@ -416,7 +416,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
416
416
  version: '0'
417
417
  requirements: []
418
418
  rubygems_version: 3.2.33
419
- signing_key:
419
+ signing_key:
420
420
  specification_version: 4
421
421
  summary: Another business actions architecture for Rails apps
422
422
  test_files: []