testingrecord 0.3 → 0.4.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: a976787fabb7a7f44edd0023cccee5c2885aab6ae6712762682984564b61a241
4
- data.tar.gz: 1844f8b3fccd0ef7346826ab10cddd346d79e35f7832e6f406ee7103c89d8422
3
+ metadata.gz: 1cdf9a8f41b762bd4fd516fadce6f8e5afb21f5953398db4f5108ddc73e2a83a
4
+ data.tar.gz: c90170893784153947669a66fb7e5c806adaeb11345c1fea23aef9b310a90260
5
5
  SHA512:
6
- metadata.gz: a7a5bea3abcdebf53465684ad24cfa5c101a64a921486873bc68675854a42994d6f80b102c91b753747444e57713479827ec2b11231a6ae9108a973806938aef
7
- data.tar.gz: 0b7919a99e0bbd4a7f6e37e4530259fc6a83b51935edae3ff83e2f1f6c6133d6ef4308e81abc7837e5b91c5dc7b88873123dcc8779518ce0ffe62b49fc28ed8c
6
+ metadata.gz: 67c56dc0c57152a7d042cd0b138b9c73dabe6daf0b453cd90c2ec3d84f0f091ae54838d2c09afea15c5221092e423d44d94ff085e71094caf0463b48dd0b994f
7
+ data.tar.gz: 6ae0747a2cda0681b61e66a78f918c20a7ed320c1745150078747e66cbcb4beaccf8e8f6a18f932cfb5019cd09a6ea4e7437134e63f6f2887db9981f33e7c05b
@@ -8,37 +8,26 @@ 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)
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)
26
26
  define_method(:"#{name}?") do
27
- instance_variable_get(:"@#{name}").any?
27
+ obj = send(name)
28
+ !(obj.nil? || obj.empty?)
28
29
  end
29
30
  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
31
  end
43
32
  end
44
33
  end
@@ -0,0 +1,55 @@
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
25
+ #
26
+ # @return [Array<Symbol>]
27
+ def attribute(name)
28
+ attr_reader name
29
+
30
+ attributes << name
31
+ end
32
+
33
+ def attributes
34
+ @attributes ||= []
35
+ end
36
+
37
+ private
38
+
39
+ def add_to_cache(entity)
40
+ self.current = entity
41
+ send(cache_name) << entity
42
+ # TODO: Add log message (Requires adding logger)
43
+ end
44
+
45
+ def cache_name
46
+ :"#{to_s.snake_case}s"
47
+ end
48
+
49
+ def ivar_name
50
+ "@#{to_s.snake_case}s"
51
+ end
52
+ end
53
+ end
54
+ end
55
+ 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,12 @@ module TestingRecord
10
10
  #
11
11
  # @return [Boolean]
12
12
  def caching_valid?(input)
13
- caching_validations.include?(input)
14
- end
15
-
16
- # Check whether the type setting is valid
17
- #
18
- # @return [Boolean]
19
- def type_valid?(input)
20
- type_validations.include?(input)
13
+ enabled_or_disabled.include?(input)
21
14
  end
22
15
 
23
16
  private
24
17
 
25
- def caching_validations = %i[enabled disabled]
26
- def type_validations = %i[singular plural]
18
+ def enabled_or_disabled = %i[enabled disabled]
27
19
  end
28
20
  end
29
21
  end
@@ -7,77 +7,30 @@ 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 attribute that was provided
26
21
  #
27
22
  # @return [TestingRecord::Model]
28
- def create(attributes = {})
23
+ def create(attributes = self.attributes)
29
24
  new(attributes).tap do |entity|
25
+ attributes.each do |attribute_key, attribute_value|
26
+ entity.instance_variable_set("@#{attribute_key}", attribute_value)
27
+ attr_reader attribute_key
28
+ end
30
29
  add_to_cache(entity) if respond_to?(cache_name)
31
30
  end
32
31
  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
32
  end
78
33
 
79
- attr_reader :attributes
80
-
81
34
  def initialize(attributes = {})
82
35
  @attributes = attributes
83
36
  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.1'
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.1
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-22 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: []