nueca_rails_interfaces 0.1.0 → 0.2.0
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 +4 -4
- data/.byebug_history +7 -0
- data/.rubocop.yml +3 -0
- data/lib/nueca_rails_interfaces/version.rb +1 -1
- data/lib/nueca_rails_interfaces.rb +1 -1
- data/lib/v1/data_source/base_interface.rb +57 -0
- data/lib/v1/data_source/node_interface.rb +24 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47ab3f86ff621775d71991416b5abd7c755d8a6921e11ea6190b9476a31239b6
|
4
|
+
data.tar.gz: e697386fabbfd938c02432ebcad2b2e8009871711ced5b935082d170c210bfc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecdf54e8ff4b9c33d339c95dae9b10cec5c84f959efdf6c233a20fe3c2aaf5f2cedfb82ba04f6ef30b3116ff1d234044dc5ed115003cad9c779eb3da47a29e00
|
7
|
+
data.tar.gz: da5d35c270499d55264f18475702e42e6df2a76478291bc18648da33bd94db02f7615c10edb550ae07472e247a5d3809cd24da668bb7f1e17bad0ee27f35c9f1
|
data/.byebug_history
ADDED
data/.rubocop.yml
CHANGED
@@ -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
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tien
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-02 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.
|
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.
|