testingrecord 0.6 → 0.8
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/lib/testing_record/dsl/builder/helpers.rb +10 -7
- data/lib/testing_record/dsl/builder/settings.rb +0 -13
- data/lib/testing_record/model.rb +43 -16
- data/lib/testing_record/version.rb +1 -1
- data/lib/testing_record.rb +18 -0
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63ee9271871c1194e05e12d7f4d5d23bc744f703461b8519d45300f180f5432c
|
|
4
|
+
data.tar.gz: 251d286e38df1ed55a6e25f40c615ca7ccc1673c50758ab0bec861eabc354da7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45cc639fbc3e7d7ca82c4d08ad4a867f7ff550a78738de717ca07ae7b3fa5e6bf7b9991f07bc745690eab33db0e2a39a58cb8f1fb61f259567280651941630bb
|
|
7
|
+
data.tar.gz: 68975a0f8c4efbe1ed14aab9e47f0809c6f58377c5f587aa20c5192847869ff15becb145356d06a1a8fd78c1a3257e43ee85184806f91a40ed71eda331ba978c
|
|
@@ -6,17 +6,20 @@ module TestingRecord
|
|
|
6
6
|
# [TestingRecord::DSL::Builder::Helpers]
|
|
7
7
|
# Ways in which we can build in extra helper methods from building requests
|
|
8
8
|
module Helpers
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def add_helpers
|
|
13
|
-
attributes.each do |attribute|
|
|
14
|
-
add_presence_helper(attribute)
|
|
15
|
-
end
|
|
9
|
+
# DSL signature to add all helpers - Should be procedurally called in the class definition
|
|
10
|
+
def include_helpers
|
|
11
|
+
@include_helpers = true
|
|
16
12
|
end
|
|
17
13
|
|
|
18
14
|
private
|
|
19
15
|
|
|
16
|
+
# Top level wrapper method that will incrementally add each helper (Currently only one)
|
|
17
|
+
def add_helpers(attributes)
|
|
18
|
+
attributes.each_key do |attribute|
|
|
19
|
+
add_presence_helper(attribute)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
20
23
|
# Add the boolean helper which will perform a check to determine whether...
|
|
21
24
|
# For singular / default categorisations, this checks if one has been set over the default empty value
|
|
22
25
|
# For plural attributes whether the array has any values
|
|
@@ -12,19 +12,6 @@ module TestingRecord
|
|
|
12
12
|
|
|
13
13
|
attr_reader :__primary_key
|
|
14
14
|
|
|
15
|
-
# Sets an attribute on the model
|
|
16
|
-
#
|
|
17
|
-
# @return [Array<Symbol>]
|
|
18
|
-
def attribute(name)
|
|
19
|
-
attr_reader name
|
|
20
|
-
|
|
21
|
-
attributes << name
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def attributes
|
|
25
|
-
@attributes ||= []
|
|
26
|
-
end
|
|
27
|
-
|
|
28
15
|
# Create a cache of the entities, named according to the classname
|
|
29
16
|
#
|
|
30
17
|
# @return [Symbol]
|
data/lib/testing_record/model.rb
CHANGED
|
@@ -14,34 +14,61 @@ module TestingRecord
|
|
|
14
14
|
attr_reader :attributes
|
|
15
15
|
|
|
16
16
|
class << self
|
|
17
|
-
|
|
17
|
+
attr_reader :current
|
|
18
18
|
|
|
19
19
|
# Creates an instance of the model
|
|
20
20
|
# -> Creating iVar values for each attribute that was provided
|
|
21
21
|
# -> Adding it to the cache if caching is enabled
|
|
22
|
+
# -> Keeping a track of all originally supplied attributes in symbolized format in the `attributes` iVar
|
|
22
23
|
#
|
|
23
24
|
# @return [TestingRecord::Model]
|
|
24
|
-
def create(attributes
|
|
25
|
-
new(attributes).tap do |entity|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
break entity unless respond_to?(:all)
|
|
32
|
-
|
|
33
|
-
self.current = entity
|
|
34
|
-
all << entity
|
|
35
|
-
TestingRecord.logger.debug("Entity: #{entity} added to cache")
|
|
25
|
+
def create(attributes)
|
|
26
|
+
new(attributes.transform_keys(&:to_sym)).tap do |entity|
|
|
27
|
+
configure_data(entity, attributes)
|
|
28
|
+
add_helpers(attributes) if entity.class.instance_variable_get(:@include_helpers)
|
|
29
|
+
cache_entity(entity)
|
|
36
30
|
end
|
|
37
31
|
end
|
|
38
32
|
|
|
33
|
+
def current=(entity)
|
|
34
|
+
if entity
|
|
35
|
+
TestingRecord.logger.info("Switching current user from #{@current} to #{entity}")
|
|
36
|
+
else
|
|
37
|
+
TestingRecord.logger.info("Purging current user: #{@current}")
|
|
38
|
+
end
|
|
39
|
+
@current = entity
|
|
40
|
+
end
|
|
41
|
+
|
|
39
42
|
# Deletes the instance of the model from the cache (Does nothing if caching is disabled)
|
|
40
43
|
#
|
|
41
44
|
# @return [TestingRecord::Model]
|
|
42
45
|
def delete(entity)
|
|
43
46
|
all.delete(entity) if respond_to?(:all)
|
|
44
47
|
end
|
|
48
|
+
|
|
49
|
+
# Deletes the instance of the model from the cache (Does nothing if caching is disabled)
|
|
50
|
+
#
|
|
51
|
+
# @return [TestingRecord::Model]
|
|
52
|
+
def delete_by_id(id)
|
|
53
|
+
delete(with_id(id)) if respond_to?(:all)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def cache_entity(entity)
|
|
59
|
+
return unless respond_to?(:all)
|
|
60
|
+
|
|
61
|
+
self.current = entity
|
|
62
|
+
all << entity
|
|
63
|
+
TestingRecord.logger.debug("Entity: #{entity} added to cache")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def configure_data(entity, attributes)
|
|
67
|
+
attributes.each do |attribute_key, attribute_value|
|
|
68
|
+
entity.instance_variable_set("@#{attribute_key}", attribute_value)
|
|
69
|
+
entity.class.attr_reader attribute_key
|
|
70
|
+
end
|
|
71
|
+
end
|
|
45
72
|
end
|
|
46
73
|
|
|
47
74
|
def initialize(attributes = {})
|
|
@@ -64,15 +91,15 @@ module TestingRecord
|
|
|
64
91
|
end
|
|
65
92
|
|
|
66
93
|
# Updates an entity (instance), of a model
|
|
67
|
-
# -> Updating iVar values for each attribute that was provided
|
|
94
|
+
# -> Updating iVar values for each attribute that was provided (Converting to symbolized format)
|
|
68
95
|
# -> It will **not** create new reader methods for new variables added
|
|
69
96
|
#
|
|
70
97
|
# @return [TestingRecord::Model]
|
|
71
98
|
def update(attrs)
|
|
72
|
-
attrs.each do |key, value|
|
|
99
|
+
attrs.transform_keys(&:to_sym).each do |key, value|
|
|
73
100
|
attributes[key] = value
|
|
74
101
|
instance_variable_set("@#{key}", value)
|
|
75
|
-
TestingRecord.logger.info("Updated '#{key}' on
|
|
102
|
+
TestingRecord.logger.info("Updated '#{key}' on the #{self.class} entity to be '#{value}'")
|
|
76
103
|
end
|
|
77
104
|
self
|
|
78
105
|
end
|
data/lib/testing_record.rb
CHANGED
|
@@ -32,5 +32,23 @@ module TestingRecord
|
|
|
32
32
|
def log_path=(logdev)
|
|
33
33
|
logger.reopen(logdev)
|
|
34
34
|
end
|
|
35
|
+
|
|
36
|
+
# To enable full logging (This uses the Ruby API, so can accept any of a
|
|
37
|
+
# Symbol / String / Integer as an input
|
|
38
|
+
# TestingRecord.log_level = :DEBUG
|
|
39
|
+
# TestingRecord.log_level = 'DEBUG'
|
|
40
|
+
# TestingRecord.log_level = 0
|
|
41
|
+
#
|
|
42
|
+
# To disable all logging
|
|
43
|
+
# TestingRecord.log_level = :UNKNOWN
|
|
44
|
+
def log_level=(value)
|
|
45
|
+
logger.level = value
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# To query what level is being logged
|
|
49
|
+
# TestingRecord.log_level # => :DEBUG # By default
|
|
50
|
+
def log_level
|
|
51
|
+
%i[DEBUG INFO WARN ERROR FATAL UNKNOWN][logger.level]
|
|
52
|
+
end
|
|
35
53
|
end
|
|
36
54
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: testingrecord
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '0.
|
|
4
|
+
version: '0.8'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Luke Hill
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-03-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: automation_helpers
|
|
@@ -19,7 +19,7 @@ dependencies:
|
|
|
19
19
|
version: '5'
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '
|
|
22
|
+
version: '8'
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -29,7 +29,7 @@ dependencies:
|
|
|
29
29
|
version: '5'
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '8'
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
34
|
name: logger
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -64,28 +64,28 @@ dependencies:
|
|
|
64
64
|
requirements:
|
|
65
65
|
- - "~>"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: 1.
|
|
67
|
+
version: 1.85.1
|
|
68
68
|
type: :development
|
|
69
69
|
prerelease: false
|
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
71
71
|
requirements:
|
|
72
72
|
- - "~>"
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: 1.
|
|
74
|
+
version: 1.85.1
|
|
75
75
|
- !ruby/object:Gem::Dependency
|
|
76
76
|
name: rubocop-performance
|
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
|
78
78
|
requirements:
|
|
79
79
|
- - "~>"
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: 1.
|
|
81
|
+
version: 1.26.1
|
|
82
82
|
type: :development
|
|
83
83
|
prerelease: false
|
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
|
86
86
|
- - "~>"
|
|
87
87
|
- !ruby/object:Gem::Version
|
|
88
|
-
version: 1.
|
|
88
|
+
version: 1.26.1
|
|
89
89
|
- !ruby/object:Gem::Dependency
|
|
90
90
|
name: rubocop-rspec
|
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|