nueca_rails_interfaces 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71471580cc28c42f5997160d6e01684e081244da014e44ecd110e37e4c62db91
4
- data.tar.gz: 3236fcf542d757322a14ab338330ad721089445afc4f7b1877bd45cf6dbeda65
3
+ metadata.gz: c0400fd054522afaa27869d22bbeb107f9c84e5f9989fd28538818ab278333cc
4
+ data.tar.gz: 9042cd34c04d336eb24dc8ed33df148d090b23a0ecf1f56364cfeac3133a3723
5
5
  SHA512:
6
- metadata.gz: '089db05b4843a21ba0462efe9e07717a6b17f8e35117fcb096279d0f136f1f6828ed7c7d85f423e38781f325b58e678bb4a8f0808010daee14f530716d5ede3c'
7
- data.tar.gz: 6061f449b9deb9130c7aeaba1d5de4a7a02542bc560333dc1995a088771a88f9f2a23e67eeb0e947b25a340e804f74b5eb8f1aef157d8900dccec7cd685136a7
6
+ metadata.gz: f2f1b0886cd7b2c9659533e080409a6749f50a07bcf6c365a23f49f208e6d782ff6bfab652e49fe3e21c326f258d0da35c6e2d84a978ed1c9ae5769873af7de0
7
+ data.tar.gz: 8256f7c51cd8ba02b7217bed745bbbeb7c5a12fec2642506c6b18660c6938f35fa8098a9314e2baa969be43c28684070c78596c34464b8c075c59c79f97ae5f8
data/.byebug_history ADDED
@@ -0,0 +1,7 @@
1
+ exit
2
+ defined?(Node)
3
+ c
4
+ exit
5
+ defined?(Node)
6
+ exit
7
+ c
data/.rubocop.yml CHANGED
@@ -12,3 +12,6 @@ Layout/LineLength:
12
12
 
13
13
  RSpec/NestedGroups:
14
14
  Max: 5
15
+
16
+ RSpec/VerifiedDoubles:
17
+ Enabled: false
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NuecaRailsInterfaces
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -13,4 +13,4 @@ end
13
13
  require_relative 'nueca_rails_interfaces/util'
14
14
 
15
15
  # Require all interfaces.
16
- Dir["#{__dir__}/v*/*_interface.rb"].each { |file| require_relative file }
16
+ Dir["#{__dir__}/v*/**/*_interface.rb"].each { |file| require_relative file }
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module V1
4
+ module DataSource
5
+ # Error class for when the data source class is not found. Only use this for the context of data sources.
6
+ class NotFound < StandardError; end
7
+
8
+ # The data source base. Extend this module to create a data source base.
9
+ # It is used to invoke the data source so that it automatically searches for data source nodes
10
+ # based on the type of the record.
11
+ module BaseInterface
12
+ # Creates a new data source instance for the given record.
13
+ # It will return the data source node class instance instead of itself.
14
+ # Do not override.
15
+ def new(record)
16
+ record = modify_record(record)
17
+ data_source = data_source_class(record).new(record)
18
+ modify_data_source(data_source)
19
+ end
20
+
21
+ private
22
+
23
+ # Hook for easily altering the record for processing. Override this instead of new.
24
+ # Make sure this returns the record.
25
+ def modify_record(record)
26
+ record
27
+ end
28
+
29
+ # Hook for easily altering the detected data source for processing. Override this instead of new.
30
+ # Make sure this returns an object that includes DataSource::Node.
31
+ def modify_data_source(data_source)
32
+ data_source
33
+ end
34
+
35
+ # Method responsible for finding the data source node for the given record. Do not override.
36
+ # It raises a DataSouce::NotFound error if the node is not found.
37
+ def data_source_class(record)
38
+ resolver_logic(record)
39
+ rescue NameError
40
+ raise NotFound, 'Data Source node not found. Please check the namespace and class ' \
41
+ "name for #{record.class.name}#{" in #{namespace}" if namespace.present?}."
42
+ end
43
+
44
+ # Contains the logic on how to resolve the constants toward the data source node classes.
45
+ # Override this instead of data_source_class.
46
+ def resolver_logic(record)
47
+ "#{namespace}::#{record.class.name}Ds".constantize
48
+ end
49
+
50
+ # Returns the namespace of the data source base automatically.
51
+ # Override if needed when there is a different file stucture and different namespace.
52
+ def namespace
53
+ name.split('::')[0...-1].join('::')
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module V1
4
+ module DataSource
5
+ # Data source node. They are used as actual sources of data for records,
6
+ # may it be in terms of presentation or multiple sources of basis for data.
7
+ # Include this module to create a data source node.
8
+ module NodeInterface
9
+ class << self
10
+ # Automatically delegate missing methods to the record.
11
+ def included(subclass)
12
+ subclass.delegate_missing_to(:record)
13
+ end
14
+ end
15
+
16
+ attr_reader :record
17
+
18
+ # The record itself!
19
+ def initialize(record)
20
+ @record = record
21
+ end
22
+ end
23
+ end
24
+ end
@@ -17,6 +17,15 @@ module V1
17
17
  # @return [void]
18
18
  def self.included(base)
19
19
  base.include(ActiveModel::Model)
20
+ Rails.logger.warn(
21
+ <<~MSG
22
+ ##############################################
23
+ # DEPRECATION WARNING #
24
+ # V1::FormInterface will be deprecated soon. #
25
+ # Please use V2::FormInterface instead. #
26
+ ##############################################
27
+ MSG
28
+ )
20
29
  end
21
30
 
22
31
  # Final attributes to be returned by the form after validation.
@@ -13,6 +13,18 @@ module V1
13
13
  # All services will have a `data` method that will contain the resulting data that the service produced.
14
14
  # Developers will mainly override `action` method and `data method`.
15
15
  module ServiceInterface
16
+ def self.included(_)
17
+ Rails.logger.warn(
18
+ <<~MSG
19
+ #################################################
20
+ # DEPRECATION WARNING #
21
+ # V1::ServiceInterface will be deprecated soon. #
22
+ # Please use V2::ServiceInterface instead. #
23
+ #################################################
24
+ MSG
25
+ )
26
+ end
27
+
16
28
  # This is the main method of the service. This is the method that should be called to perform the service.
17
29
  # Do not override this method. Instead, override the `action` method.
18
30
  # @return [self] Instance of the service.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nueca_rails_interfaces
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tien
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-06 00:00:00.000000000 Z
11
+ date: 2024-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -45,6 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".byebug_history"
48
49
  - ".rspec"
49
50
  - ".rubocop.yml"
50
51
  - CODE_OF_CONDUCT.md
@@ -54,6 +55,8 @@ files:
54
55
  - lib/nueca_rails_interfaces.rb
55
56
  - lib/nueca_rails_interfaces/util.rb
56
57
  - lib/nueca_rails_interfaces/version.rb
58
+ - lib/v1/data_source/base_interface.rb
59
+ - lib/v1/data_source/node_interface.rb
57
60
  - lib/v1/form_interface.rb
58
61
  - lib/v1/query_interface.rb
59
62
  - lib/v1/service_interface.rb
@@ -80,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
83
  - !ruby/object:Gem::Version
81
84
  version: '0'
82
85
  requirements: []
83
- rubygems_version: 3.5.10
86
+ rubygems_version: 3.5.11
84
87
  signing_key:
85
88
  specification_version: 4
86
89
  summary: Interfaces for known object entities in Rails Development at Nueca.