testingrecord 0.3 → 0.4

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: a976787fabb7a7f44edd0023cccee5c2885aab6ae6712762682984564b61a241
4
- data.tar.gz: 1844f8b3fccd0ef7346826ab10cddd346d79e35f7832e6f406ee7103c89d8422
3
+ metadata.gz: 6f6570d13d91ba9f4785d7ea4c2be9c742710339406337c0c70c2095c727aa97
4
+ data.tar.gz: 9e94862ed788d679feb98ad62a83c7aac84d3062931f2121bc6997f10ee86bd1
5
5
  SHA512:
6
- metadata.gz: a7a5bea3abcdebf53465684ad24cfa5c101a64a921486873bc68675854a42994d6f80b102c91b753747444e57713479827ec2b11231a6ae9108a973806938aef
7
- data.tar.gz: 0b7919a99e0bbd4a7f6e37e4530259fc6a83b51935edae3ff83e2f1f6c6133d6ef4308e81abc7837e5b91c5dc7b88873123dcc8779518ce0ffe62b49fc28ed8c
6
+ metadata.gz: f7f46a7072f63f08f67502bc6fb4076a7eec22d2bd3942670f871ef2df267e019a8bbc0edefc28d97792ce3cb6b504c3326b81026efda330ef508dfb96856f12
7
+ data.tar.gz: e4c3fad3c5b588fd8a4db23bd27b106c509d7314bd34d008d4aef379cadc8c68fdc317d124862282dd9194969dc31cdacdec7968c786db1c724675055ca1a3be
@@ -8,37 +8,25 @@ module TestingRecord
8
8
  module Helpers
9
9
  # Method to add all helpers - Should be called last in the DSL invocations in the class definition
10
10
  #
11
- # @return [TestingRecord::Model]
11
+ # @return [Array]
12
12
  def add_helpers
13
- properties.each do |hash|
14
- if hash[:type] == :singular
15
- add_any_helper(hash[:name])
16
- else
17
- add_any_helper("#{hash[:name]}s")
18
- end
13
+ attributes.each do |attribute|
14
+ add_presence_helper(attribute[:name], attribute[:type])
19
15
  end
20
16
  end
21
17
 
22
- # Add the boolean helper which will perform the `#any?` check on your instance
18
+ private
19
+
20
+ # Add the boolean helper which will perform a check to determine whether...
21
+ # For singular / default categorisations, this checks if one has been set over the default empty value
22
+ # For plural attributes whether the array has any values
23
23
  #
24
24
  # @return [TestingRecord::Model]
25
- def add_any_helper(name)
25
+ def add_presence_helper(name, type)
26
26
  define_method(:"#{name}?") do
27
- instance_variable_get(:"@#{name}").any?
27
+ type == :plural ? send(:name).any? : send(:name).empty?
28
28
  end
29
29
  end
30
-
31
- # Check whether the type setting is valid
32
- #
33
- # @return [Boolean]
34
- def type_valid?(input)
35
- type_validations.include?(input)
36
- end
37
-
38
- private
39
-
40
- def caching_validations = %i[enabled disabled]
41
- def type_validations = %i[singular plural]
42
30
  end
43
31
  end
44
32
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../validation'
4
+
5
+ module TestingRecord
6
+ module DSL
7
+ module Builder
8
+ # [TestingRecord::DSL::Builder::Settings]
9
+ # Ways in which we can configure our individual models
10
+ module Settings
11
+ include DSL::Validation::Input
12
+
13
+ # Create a cache of the entities, named according to the classname
14
+ #
15
+ # @return [Symbol]
16
+ def caching(option)
17
+ raise Error, 'Invalid caching option, must be :enabled or :disabled' unless caching_valid?(option)
18
+ return unless option == :enabled
19
+
20
+ instance_variable_set(ivar_name, [])
21
+ define_singleton_method(cache_name) { instance_variable_get(ivar_name) }
22
+ end
23
+
24
+ # Sets an attribute on the model, this should have a name and an optional type (Defaults to `:singular`)
25
+ #
26
+ # @return [Array<Hash>]
27
+ def attribute(name, type: :singular)
28
+ raise Error, 'Invalid type option, must be :singular or :plural if specified' unless type_valid?(type)
29
+
30
+ attr_reader name
31
+
32
+ attributes << { name:, type: }
33
+ end
34
+
35
+ def attributes
36
+ @attributes ||= []
37
+ end
38
+
39
+ # Set the type of model, this should be one of `:singular` or `:plural`
40
+ #
41
+ # @return [Symbol]
42
+ def type(option)
43
+ raise Error, 'Invalid type option, must be :singular or :plural' unless type_valid?(option)
44
+
45
+ @type = option
46
+ end
47
+
48
+ private
49
+
50
+ def add_to_cache(entity)
51
+ self.current = entity
52
+ send(cache_name) << entity
53
+ # TODO: Add log message (Requires adding logger)
54
+ end
55
+
56
+ def cache_name
57
+ :"#{to_s.snake_case}s"
58
+ end
59
+
60
+ def ivar_name
61
+ "@#{to_s.snake_case}s"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'builder/helpers'
4
+ require_relative 'builder/settings'
@@ -10,20 +10,20 @@ module TestingRecord
10
10
  #
11
11
  # @return [Boolean]
12
12
  def caching_valid?(input)
13
- caching_validations.include?(input)
13
+ enabled_or_disabled.include?(input)
14
14
  end
15
15
 
16
16
  # Check whether the type setting is valid
17
17
  #
18
18
  # @return [Boolean]
19
19
  def type_valid?(input)
20
- type_validations.include?(input)
20
+ singular_or_plural.include?(input)
21
21
  end
22
22
 
23
23
  private
24
24
 
25
- def caching_validations = %i[enabled disabled]
26
- def type_validations = %i[singular plural]
25
+ def enabled_or_disabled = %i[enabled disabled]
26
+ def singular_or_plural = %i[singular plural]
27
27
  end
28
28
  end
29
29
  end
@@ -7,77 +7,31 @@ module TestingRecord
7
7
  # The top level Model. Most of the behaviours specified here are fairly rudimentary ones that will then
8
8
  # include other behaviour(s), from the included modules
9
9
  class Model
10
- extend DSL::Validation::Input
11
10
  extend DSL::Builder::Helpers
11
+ extend DSL::Builder::Settings
12
12
 
13
- class << self
14
- # Create a cache of the entities, named according to the classname
15
- #
16
- # @return [Symbol]
17
- def caching(option)
18
- raise Error, 'Invalid caching option, must be :enabled or :disabled' unless caching_valid?(option)
19
- return unless option == :enabled
13
+ attr_reader :attributes
20
14
 
21
- instance_variable_set(ivar_name, [])
22
- define_singleton_method(cache_name) { instance_variable_get(ivar_name) }
23
- end
15
+ class << self
16
+ attr_accessor :current
24
17
 
25
- # Creates an instance of the model, adding it to the cache if caching is enabled
18
+ # Creates an instance of the model
19
+ # -> Adding it to the cache if caching is enabled
20
+ # -> Creating iVar values for each property that was set
21
+ # -> For now these will be set to `''` or `[]`
26
22
  #
27
23
  # @return [TestingRecord::Model]
28
- def create(attributes = {})
24
+ def create(attributes = self.attributes)
29
25
  new(attributes).tap do |entity|
26
+ attributes.each do |attribute|
27
+ default_value = attribute[:type] == :singular ? '' : []
28
+ entity.instance_variable_set("@#{attribute[:name]}", default_value)
29
+ end
30
30
  add_to_cache(entity) if respond_to?(cache_name)
31
31
  end
32
32
  end
33
-
34
- # Sets a property on the model, this should have a name and an optional type (Defaults to `:singular`)
35
- #
36
- # @return [Array<Hash>]
37
- def property(name, type: :singular)
38
- raise Error, 'Invalid type option, must be :singular or :plural' unless type_valid?(type)
39
-
40
- if type == :plural
41
- attr_reader :"#{name}s"
42
- else
43
- attr_reader name
44
- end
45
-
46
- properties << { name:, type: }
47
- end
48
-
49
- def properties
50
- @properties ||= []
51
- end
52
-
53
- # Set the type of model, this should be one of `:singular` or `:plural`
54
- #
55
- # @return [Symbol]
56
- def type(option)
57
- raise Error, 'Invalid type option, must be :singular or :plural' unless type_valid?(option)
58
-
59
- @type = option
60
- end
61
-
62
- private
63
-
64
- def add_to_cache(entity)
65
- # TODO: Cache entity as the current entity for model class
66
- send(cache_name) << entity
67
- # TODO: Add log message (Requires adding logger)
68
- end
69
-
70
- def cache_name
71
- :"#{to_s.snake_case}s"
72
- end
73
-
74
- def ivar_name
75
- "@#{to_s.snake_case}s"
76
- end
77
33
  end
78
34
 
79
- attr_reader :attributes
80
-
81
35
  def initialize(attributes = {})
82
36
  @attributes = attributes
83
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestingRecord
4
- VERSION = '0.3'
4
+ VERSION = '0.4'
5
5
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testingrecord
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Hill
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 2025-09-09 00:00:00.000000000 Z
11
+ date: 2025-12-16 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: automation_helpers
@@ -29,56 +30,56 @@ dependencies:
29
30
  requirements:
30
31
  - - "~>"
31
32
  - !ruby/object:Gem::Version
32
- version: '3.12'
33
+ version: '3.13'
33
34
  type: :development
34
35
  prerelease: false
35
36
  version_requirements: !ruby/object:Gem::Requirement
36
37
  requirements:
37
38
  - - "~>"
38
39
  - !ruby/object:Gem::Version
39
- version: '3.12'
40
+ version: '3.13'
40
41
  - !ruby/object:Gem::Dependency
41
42
  name: rubocop
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - "~>"
45
46
  - !ruby/object:Gem::Version
46
- version: 1.59.0
47
+ version: 1.81.0
47
48
  type: :development
48
49
  prerelease: false
49
50
  version_requirements: !ruby/object:Gem::Requirement
50
51
  requirements:
51
52
  - - "~>"
52
53
  - !ruby/object:Gem::Version
53
- version: 1.59.0
54
+ version: 1.81.0
54
55
  - !ruby/object:Gem::Dependency
55
56
  name: rubocop-performance
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - "~>"
59
60
  - !ruby/object:Gem::Version
60
- version: 1.20.0
61
+ version: 1.25.0
61
62
  type: :development
62
63
  prerelease: false
63
64
  version_requirements: !ruby/object:Gem::Requirement
64
65
  requirements:
65
66
  - - "~>"
66
67
  - !ruby/object:Gem::Version
67
- version: 1.20.0
68
+ version: 1.25.0
68
69
  - !ruby/object:Gem::Dependency
69
70
  name: rubocop-rspec
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - "~>"
73
74
  - !ruby/object:Gem::Version
74
- version: 2.25.0
75
+ version: 3.7.0
75
76
  type: :development
76
77
  prerelease: false
77
78
  version_requirements: !ruby/object:Gem::Requirement
78
79
  requirements:
79
80
  - - "~>"
80
81
  - !ruby/object:Gem::Version
81
- version: 2.25.0
82
+ version: 3.7.0
82
83
  description: Use metaprogrammed cache-models to store data you create on-the-fly.
83
84
  Access and retrieve references to data created from any place inside your tests.
84
85
  email:
@@ -93,6 +94,7 @@ files:
93
94
  - lib/testing_record/dsl.rb
94
95
  - lib/testing_record/dsl/builder.rb
95
96
  - lib/testing_record/dsl/builder/helpers.rb
97
+ - lib/testing_record/dsl/builder/settings.rb
96
98
  - lib/testing_record/dsl/validation.rb
97
99
  - lib/testing_record/dsl/validation/input.rb
98
100
  - lib/testing_record/model.rb
@@ -104,6 +106,7 @@ metadata:
104
106
  changelog_uri: https://github.com/site-prism/testingrecord/blob/main/CHANGELOG.md
105
107
  homepage_uri: https://github.com/site-prism/testingrecord
106
108
  source_code_uri: https://github.com/site-prism/testingrecord
109
+ post_install_message:
107
110
  rdoc_options: []
108
111
  require_paths:
109
112
  - lib
@@ -118,7 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
121
  - !ruby/object:Gem::Version
119
122
  version: '0'
120
123
  requirements: []
121
- rubygems_version: 3.6.2
124
+ rubygems_version: 3.3.27
125
+ signing_key:
122
126
  specification_version: 4
123
127
  summary: Thread based caching system to store and edit records
124
128
  test_files: []