testingrecord 0.4 → 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: 6f6570d13d91ba9f4785d7ea4c2be9c742710339406337c0c70c2095c727aa97
4
- data.tar.gz: 9e94862ed788d679feb98ad62a83c7aac84d3062931f2121bc6997f10ee86bd1
3
+ metadata.gz: 1cdf9a8f41b762bd4fd516fadce6f8e5afb21f5953398db4f5108ddc73e2a83a
4
+ data.tar.gz: c90170893784153947669a66fb7e5c806adaeb11345c1fea23aef9b310a90260
5
5
  SHA512:
6
- metadata.gz: f7f46a7072f63f08f67502bc6fb4076a7eec22d2bd3942670f871ef2df267e019a8bbc0edefc28d97792ce3cb6b504c3326b81026efda330ef508dfb96856f12
7
- data.tar.gz: e4c3fad3c5b588fd8a4db23bd27b106c509d7314bd34d008d4aef379cadc8c68fdc317d124862282dd9194969dc31cdacdec7968c786db1c724675055ca1a3be
6
+ metadata.gz: 67c56dc0c57152a7d042cd0b138b9c73dabe6daf0b453cd90c2ec3d84f0f091ae54838d2c09afea15c5221092e423d44d94ff085e71094caf0463b48dd0b994f
7
+ data.tar.gz: 6ae0747a2cda0681b61e66a78f918c20a7ed320c1745150078747e66cbcb4beaccf8e8f6a18f932cfb5019cd09a6ea4e7437134e63f6f2887db9981f33e7c05b
@@ -11,7 +11,7 @@ module TestingRecord
11
11
  # @return [Array]
12
12
  def add_helpers
13
13
  attributes.each do |attribute|
14
- add_presence_helper(attribute[:name], attribute[:type])
14
+ add_presence_helper(attribute)
15
15
  end
16
16
  end
17
17
 
@@ -22,9 +22,10 @@ module TestingRecord
22
22
  # For plural attributes whether the array has any values
23
23
  #
24
24
  # @return [TestingRecord::Model]
25
- def add_presence_helper(name, type)
25
+ def add_presence_helper(name)
26
26
  define_method(:"#{name}?") do
27
- type == :plural ? send(:name).any? : send(:name).empty?
27
+ obj = send(name)
28
+ !(obj.nil? || obj.empty?)
28
29
  end
29
30
  end
30
31
  end
@@ -21,30 +21,19 @@ module TestingRecord
21
21
  define_singleton_method(cache_name) { instance_variable_get(ivar_name) }
22
22
  end
23
23
 
24
- # Sets an attribute on the model, this should have a name and an optional type (Defaults to `:singular`)
24
+ # Sets an attribute on the model
25
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
-
26
+ # @return [Array<Symbol>]
27
+ def attribute(name)
30
28
  attr_reader name
31
29
 
32
- attributes << { name:, type: }
30
+ attributes << name
33
31
  end
34
32
 
35
33
  def attributes
36
34
  @attributes ||= []
37
35
  end
38
36
 
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
37
  private
49
38
 
50
39
  def add_to_cache(entity)
@@ -13,17 +13,9 @@ module TestingRecord
13
13
  enabled_or_disabled.include?(input)
14
14
  end
15
15
 
16
- # Check whether the type setting is valid
17
- #
18
- # @return [Boolean]
19
- def type_valid?(input)
20
- singular_or_plural.include?(input)
21
- end
22
-
23
16
  private
24
17
 
25
18
  def enabled_or_disabled = %i[enabled disabled]
26
- def singular_or_plural = %i[singular plural]
27
19
  end
28
20
  end
29
21
  end
@@ -17,15 +17,14 @@ module TestingRecord
17
17
 
18
18
  # Creates an instance of the model
19
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 `[]`
20
+ # -> Creating iVar values for each attribute that was provided
22
21
  #
23
22
  # @return [TestingRecord::Model]
24
23
  def create(attributes = self.attributes)
25
24
  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)
25
+ attributes.each do |attribute_key, attribute_value|
26
+ entity.instance_variable_set("@#{attribute_key}", attribute_value)
27
+ attr_reader attribute_key
29
28
  end
30
29
  add_to_cache(entity) if respond_to?(cache_name)
31
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestingRecord
4
- VERSION = '0.4'
4
+ VERSION = '0.4.1'
5
5
  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'
4
+ version: 0.4.1
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-16 00:00:00.000000000 Z
11
+ date: 2025-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: automation_helpers