testingrecord 0.4.1 → 0.5

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: 1cdf9a8f41b762bd4fd516fadce6f8e5afb21f5953398db4f5108ddc73e2a83a
4
- data.tar.gz: c90170893784153947669a66fb7e5c806adaeb11345c1fea23aef9b310a90260
3
+ metadata.gz: 38eafdf3beadae05ae9138e4701d4644b3299dfa34e17ecb952d3f1cc7d2d3e0
4
+ data.tar.gz: beb36e06363dfaa6823f48f7b89b20502974d0d7c3f77a975991ab8e32104678
5
5
  SHA512:
6
- metadata.gz: 67c56dc0c57152a7d042cd0b138b9c73dabe6daf0b453cd90c2ec3d84f0f091ae54838d2c09afea15c5221092e423d44d94ff085e71094caf0463b48dd0b994f
7
- data.tar.gz: 6ae0747a2cda0681b61e66a78f918c20a7ed320c1745150078747e66cbcb4beaccf8e8f6a18f932cfb5019cd09a6ea4e7437134e63f6f2887db9981f33e7c05b
6
+ metadata.gz: 1e2f489178b2aa12ab5a40756495d19f78d8e5d3d40deaa5c743e0e8288f278d90325a2db6f05fdfef40753360869543717cbedd00756eb0d472bd1ba142db3e
7
+ data.tar.gz: da06002f629a270cafba057303a3957e118b3f87f223731e1f8d9180191293abc979553da1ae4ca21570e81a0be823f905e8c11f87ac3c84ea79f20bb77b5a3e
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestingRecord
4
+ module DSL
5
+ module Builder
6
+ # [TestingRecord::DSL::Builder::Filters]
7
+ # Ways in which we can filter our collection to find specific models
8
+ module Filters
9
+ # Checks to see whether an entity exists with the provided attributes
10
+ #
11
+ # @return [Boolean]
12
+ def exists?(attributes)
13
+ find_by(attributes).any?
14
+ end
15
+
16
+ # Finds an entity with the provided email address
17
+ # If one is found, set it as the current entity
18
+ #
19
+ # @return [TestingRecord::Model, nil]
20
+ def with_email(email_address)
21
+ find_by({ email_address: })&.first&.tap { |entity| entity.class.current = entity }
22
+ end
23
+
24
+ private
25
+
26
+ # Finds all entities that match specified attribute values
27
+ #
28
+ # @return [Array<TestingRecord::Model>]
29
+ def find_by(attributes)
30
+ pool = all
31
+ attributes.each do |key, value|
32
+ # TODO: Enable this logging once v0.5 is released with logger support
33
+ # AutomationLogger.debug("Current user pool size: #{pool.length}")
34
+ # AutomationLogger.debug("Filtering User list by #{key}: #{value}")
35
+ pool = pool.select { |entity| entity.attributes[key] == value }
36
+ end
37
+ pool
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -10,17 +10,6 @@ module TestingRecord
10
10
  module Settings
11
11
  include DSL::Validation::Input
12
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
13
  # Sets an attribute on the model
25
14
  #
26
15
  # @return [Array<Symbol>]
@@ -34,20 +23,36 @@ module TestingRecord
34
23
  @attributes ||= []
35
24
  end
36
25
 
26
+ # Create a cache of the entities, named according to the classname
27
+ #
28
+ # @return [Symbol]
29
+ def caching(option)
30
+ raise Error, 'Invalid caching option, must be :enabled or :disabled' unless caching_valid?(option)
31
+ return unless option == :enabled
32
+
33
+ instance_variable_set(:@all, [])
34
+ define_singleton_method(:all) { instance_variable_get(:@all) }
35
+ end
36
+
37
+ # Sets the primary key value of all entities - used for deduplication
38
+ # TODO: Use this for deduplication proper
39
+ #
40
+ # @return [Symbol]
41
+ def primary_key(option)
42
+ instance_variable_set(:@__primary_key, option.to_sym)
43
+ define_singleton_method(:__primary_key) { instance_variable_get(:@__primary_key) }
44
+ end
45
+
37
46
  private
38
47
 
39
48
  def add_to_cache(entity)
40
49
  self.current = entity
41
- send(cache_name) << entity
50
+ all << entity
42
51
  # TODO: Add log message (Requires adding logger)
43
52
  end
44
53
 
45
- def cache_name
46
- :"#{to_s.snake_case}s"
47
- end
48
-
49
- def ivar_name
50
- "@#{to_s.snake_case}s"
54
+ def update_cache(entity)
55
+ # TODO: This needs implementing properly
51
56
  end
52
57
  end
53
58
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'builder/filters'
3
4
  require_relative 'builder/helpers'
4
5
  require_relative 'builder/settings'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module TestingRecord
6
+ #
7
+ # @api private
8
+ #
9
+ class Logger
10
+ #
11
+ # Generate the Logger used in the gem
12
+ #
13
+ def self.create(output = $stdout)
14
+ logger = ::Logger.new(output)
15
+ logger.progname = 'Testing Record'
16
+ logger.level = :DEBUG
17
+ logger.formatter = proc do |severity, time, progname, msg|
18
+ "#{time.strftime('%F %T')} - #{severity} - #{progname} - #{msg}\n"
19
+ end
20
+
21
+ logger
22
+ end
23
+ end
24
+ end
@@ -7,6 +7,7 @@ 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::Builder::Filters
10
11
  extend DSL::Builder::Helpers
11
12
  extend DSL::Builder::Settings
12
13
 
@@ -26,7 +27,7 @@ module TestingRecord
26
27
  entity.instance_variable_set("@#{attribute_key}", attribute_value)
27
28
  attr_reader attribute_key
28
29
  end
29
- add_to_cache(entity) if respond_to?(cache_name)
30
+ add_to_cache(entity) if respond_to?(:all)
30
31
  end
31
32
  end
32
33
  end
@@ -34,5 +35,22 @@ module TestingRecord
34
35
  def initialize(attributes = {})
35
36
  @attributes = attributes
36
37
  end
38
+
39
+ def inspect
40
+ "#<#{self.class.name} #{attributes.map { |k, v| "@#{k}=#{v.inspect}" }.join(', ')}>"
41
+ end
42
+
43
+ def to_s
44
+ inspect
45
+ end
46
+
47
+ def update(attrs)
48
+ attrs.each do |key, value|
49
+ # TODO: Once logger is implemented this needs modifying to output a log message
50
+ # AutomationLogger.debug("Updating '#{key}' on current User to be '#{value}'")
51
+ attributes[key] = value
52
+ instance_variable_set("@#{key}", value)
53
+ end
54
+ end
37
55
  end
38
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestingRecord
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5'
5
5
  end
@@ -1,10 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'testing_record/dsl'
4
+ require_relative 'testing_record/logger'
4
5
  require_relative 'testing_record/model'
5
6
  require_relative 'testing_record/version'
6
7
 
8
+ # {TestingRecord} namespace
7
9
  module TestingRecord
10
+ # Generic TestingRecord error. Will be extended in the future
8
11
  class Error < StandardError; end
9
- # Your code goes here...
12
+
13
+ class << self
14
+ # The Testing Record logger object - This is called automatically in several
15
+ # locations and will log messages according to the normal Ruby protocol
16
+ #
17
+ # This logger object can also be used to manually log messages
18
+ #
19
+ # To Manually log a message
20
+ # TestingRecord.logger.info('Information')
21
+ # TestingRecord.logger.debug('Input debug message')
22
+ #
23
+ # By default the logger will output all messages to $stdout, but can be
24
+ # altered to log to a file or another IO location by calling `.log_path=`
25
+ def logger
26
+ @logger ||= Logger.create
27
+ end
28
+
29
+ # This writer method allows you to configure where you want the testingrecord logs to be sent to (Default is $stdout)
30
+ #
31
+ # Example: TestingRecord.log_path = 'testingrecord.log' would save all log messages to `./testingrecord.log`
32
+ def log_path=(logdev)
33
+ logger.reopen(logdev)
34
+ end
35
+ end
10
36
  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.1
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Hill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-12-22 00:00:00.000000000 Z
11
+ date: 2025-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: automation_helpers
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +58,14 @@ dependencies:
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 1.81.0
61
+ version: 1.82.0
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 1.81.0
68
+ version: 1.82.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rubocop-performance
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -72,16 +86,17 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 3.7.0
89
+ version: 3.8.0
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 3.7.0
83
- description: Use metaprogrammed cache-models to store data you create on-the-fly.
84
- Access and retrieve references to data created from any place inside your tests.
96
+ version: 3.8.0
97
+ description: |-
98
+ Use metaprogrammed cache-models to store data you create on-the-fly. Access and retrieve references to data \
99
+ created from any place inside your tests.
85
100
  email:
86
101
  - lukehill_uk@hotmail.com
87
102
  executables: []
@@ -93,10 +108,12 @@ files:
93
108
  - lib/testing_record.rb
94
109
  - lib/testing_record/dsl.rb
95
110
  - lib/testing_record/dsl/builder.rb
111
+ - lib/testing_record/dsl/builder/filters.rb
96
112
  - lib/testing_record/dsl/builder/helpers.rb
97
113
  - lib/testing_record/dsl/builder/settings.rb
98
114
  - lib/testing_record/dsl/validation.rb
99
115
  - lib/testing_record/dsl/validation/input.rb
116
+ - lib/testing_record/logger.rb
100
117
  - lib/testing_record/model.rb
101
118
  - lib/testing_record/version.rb
102
119
  homepage: https://github.com/site-prism/testingrecord