testingrecord 0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a976787fabb7a7f44edd0023cccee5c2885aab6ae6712762682984564b61a241
4
+ data.tar.gz: 1844f8b3fccd0ef7346826ab10cddd346d79e35f7832e6f406ee7103c89d8422
5
+ SHA512:
6
+ metadata.gz: a7a5bea3abcdebf53465684ad24cfa5c101a64a921486873bc68675854a42994d6f80b102c91b753747444e57713479827ec2b11231a6ae9108a973806938aef
7
+ data.tar.gz: 0b7919a99e0bbd4a7f6e37e4530259fc6a83b51935edae3ff83e2f1f6c6133d6ef4308e81abc7837e5b91c5dc7b88873123dcc8779518ce0ffe62b49fc28ed8c
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, SitePrism
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # testingrecord
2
+
3
+ TestingRecord - a lightweight drop-in metaprogramming framework that allows you to keep track of what
4
+ you've created on websites
5
+
6
+ - [History](#history)
7
+ - [Usage](#usage)
8
+ - [Development](#development)
9
+ - [Enabling gem methods](#enabling-gem-methods)
10
+
11
+ ## History
12
+
13
+ This in a new gem I've made to facilitate testing on websites where you want to track all data being created
14
+
15
+ This gem was made to try solve the problem where I had been caching models each time at new jobs,
16
+ hopefully some of the stuff here will be useful
17
+
18
+ The gem is currently version unstable
19
+
20
+ ## Usage
21
+
22
+ Install the gem and add to the application's Gemfile by executing:
23
+
24
+ $ bundle add testingrecord
25
+
26
+ If bundler is not being used to manage dependencies, install the gem by executing:
27
+
28
+ $ gem install testingrecord
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bundle exec rspec` to run the tests
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/site-prism/testingrecord
35
+
36
+ ## Enabling gem methods
37
+
38
+ The gem methods TODO.....
39
+
40
+ ## Usage
41
+
42
+ TODO...
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestingRecord
4
+ module DSL
5
+ module Builder
6
+ # [TestingRecord::DSL::Builder::Helpers]
7
+ # Ways in which we can build in extra helper methods from building requests
8
+ module Helpers
9
+ # Method to add all helpers - Should be called last in the DSL invocations in the class definition
10
+ #
11
+ # @return [TestingRecord::Model]
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
19
+ end
20
+ end
21
+
22
+ # Add the boolean helper which will perform the `#any?` check on your instance
23
+ #
24
+ # @return [TestingRecord::Model]
25
+ def add_any_helper(name)
26
+ define_method(:"#{name}?") do
27
+ instance_variable_get(:"@#{name}").any?
28
+ end
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
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'builder/helpers'
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestingRecord
4
+ module DSL
5
+ module Validation
6
+ # [TestingRecord::DSL::Validation::Input]
7
+ # Validations for direct inputs into creating models
8
+ module Input
9
+ # Check whether the caching setting is valid
10
+ #
11
+ # @return [Boolean]
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)
21
+ end
22
+
23
+ private
24
+
25
+ def caching_validations = %i[enabled disabled]
26
+ def type_validations = %i[singular plural]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'validation/input'
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'dsl/builder'
4
+ require_relative 'dsl/validation'
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'automation_helpers/extensions/string'
4
+ require_relative 'dsl'
5
+
6
+ module TestingRecord
7
+ # The top level Model. Most of the behaviours specified here are fairly rudimentary ones that will then
8
+ # include other behaviour(s), from the included modules
9
+ class Model
10
+ extend DSL::Validation::Input
11
+ extend DSL::Builder::Helpers
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
20
+
21
+ instance_variable_set(ivar_name, [])
22
+ define_singleton_method(cache_name) { instance_variable_get(ivar_name) }
23
+ end
24
+
25
+ # Creates an instance of the model, adding it to the cache if caching is enabled
26
+ #
27
+ # @return [TestingRecord::Model]
28
+ def create(attributes = {})
29
+ new(attributes).tap do |entity|
30
+ add_to_cache(entity) if respond_to?(cache_name)
31
+ end
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
+ end
78
+
79
+ attr_reader :attributes
80
+
81
+ def initialize(attributes = {})
82
+ @attributes = attributes
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestingRecord
4
+ VERSION = '0.3'
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'testing_record/dsl'
4
+ require_relative 'testing_record/model'
5
+ require_relative 'testing_record/version'
6
+
7
+ module TestingRecord
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testingrecord
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.3'
5
+ platform: ruby
6
+ authors:
7
+ - Luke Hill
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-09-09 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: automation_helpers
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '5.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '5.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.12'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.12'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rubocop
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 1.59.0
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.59.0
54
+ - !ruby/object:Gem::Dependency
55
+ name: rubocop-performance
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.20.0
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 1.20.0
68
+ - !ruby/object:Gem::Dependency
69
+ name: rubocop-rspec
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 2.25.0
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 2.25.0
82
+ description: Use metaprogrammed cache-models to store data you create on-the-fly.
83
+ Access and retrieve references to data created from any place inside your tests.
84
+ email:
85
+ - lukehill_uk@hotmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE
91
+ - README.md
92
+ - lib/testing_record.rb
93
+ - lib/testing_record/dsl.rb
94
+ - lib/testing_record/dsl/builder.rb
95
+ - lib/testing_record/dsl/builder/helpers.rb
96
+ - lib/testing_record/dsl/validation.rb
97
+ - lib/testing_record/dsl/validation/input.rb
98
+ - lib/testing_record/model.rb
99
+ - lib/testing_record/version.rb
100
+ homepage: https://github.com/site-prism/testingrecord
101
+ licenses: []
102
+ metadata:
103
+ bug_tracker_uri: https://github.com/site-prism/testingrecord/issues
104
+ changelog_uri: https://github.com/site-prism/testingrecord/blob/main/CHANGELOG.md
105
+ homepage_uri: https://github.com/site-prism/testingrecord
106
+ source_code_uri: https://github.com/site-prism/testingrecord
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '3.1'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 3.6.2
122
+ specification_version: 4
123
+ summary: Thread based caching system to store and edit records
124
+ test_files: []