lazy_lazer 0.5.2 → 0.5.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 +4 -4
- data/README.md +2 -2
- data/lib/lazy_lazer/internal_model.rb +2 -2
- data/lib/lazy_lazer/key_metadata.rb +0 -9
- data/lib/lazy_lazer/key_metadata_store.rb +0 -5
- data/lib/lazy_lazer/version.rb +1 -1
- data/lib/lazy_lazer.rb +3 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 733ca16c8cce77a9ba449860622b6c0d85f71228
|
4
|
+
data.tar.gz: 215967ea00e04c84130153a8c7f8bf526644c5af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a65d2e629e89fd55c9f009ae9548e436f6f90812f7f19fca63a232224c224dd59e1d9f16d0c389ab1863eed9088414947fd1a0f7bdcbf8344f97026ba7f040c3
|
7
|
+
data.tar.gz: 6d8cfc343e579b807eff4e73723c77abdb88c554c1c8b4af93e525a908018d13bca75386e689a758f7e6f217e52b24a1300cb2f4b61d4da75db412adffcb2cc0
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ require 'lazy_lazer'
|
|
8
8
|
class User
|
9
9
|
include LazyLazer
|
10
10
|
|
11
|
-
property :id, :required
|
11
|
+
property :id, :identity, :required
|
12
12
|
property :email, default: 'unknown@example.com'
|
13
13
|
property :created_at, from: :creation_time_utc, with: ->(t) { Time.at(t) }
|
14
14
|
property :age, with: :to_i
|
@@ -16,7 +16,7 @@ class User
|
|
16
16
|
property :favorite_ice_cream
|
17
17
|
|
18
18
|
def lazer_reload
|
19
|
-
|
19
|
+
fully_loaded! # mark model as fully updated
|
20
20
|
{ favorite_ice_cream: %w[vanilla strawberry chocolate].sample }
|
21
21
|
end
|
22
22
|
end
|
@@ -24,8 +24,8 @@ module LazyLazer
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# @return [Array] the identity properties
|
27
|
-
def
|
28
|
-
@key_metadata.
|
27
|
+
def required_properties
|
28
|
+
@key_metadata.required_properties
|
29
29
|
end
|
30
30
|
|
31
31
|
# Converts all unconverted keys and packages them as a hash.
|
@@ -11,9 +11,6 @@ module LazyLazer
|
|
11
11
|
# @return [Boolean] whether the key must exist when creating the model
|
12
12
|
attr_accessor :required
|
13
13
|
|
14
|
-
# @return [Boolean] whether the key is used for equality comparision
|
15
|
-
attr_accessor :identity
|
16
|
-
|
17
14
|
# @return [Boolean] whether the key must exist when loaded
|
18
15
|
attr_accessor :runtime_required
|
19
16
|
|
@@ -29,7 +26,6 @@ module LazyLazer
|
|
29
26
|
boolean_options.each_with_object(options) { |sym, hsh| hsh[sym] = true }
|
30
27
|
self.source_key = options[:from] || key_name
|
31
28
|
self.required = !!options[:required]
|
32
|
-
self.identity = !!options[:identity]
|
33
29
|
self.runtime_required = !options.key?(:default) && !options[:nil]
|
34
30
|
self.transform = options[:with]
|
35
31
|
self.default = options[:default]
|
@@ -40,11 +36,6 @@ module LazyLazer
|
|
40
36
|
@required
|
41
37
|
end
|
42
38
|
|
43
|
-
# @return [Boolean] whether the key is used for equality comparision
|
44
|
-
def identity?
|
45
|
-
@identity
|
46
|
-
end
|
47
|
-
|
48
39
|
# @return [Boolean] whether the key must exist when loaded
|
49
40
|
def runtime_required?
|
50
41
|
@runtime_required
|
@@ -6,13 +6,9 @@ module LazyLazer
|
|
6
6
|
# @return [Array<Symbol>] the required properties
|
7
7
|
attr_reader :required_properties
|
8
8
|
|
9
|
-
# @return [Array<Symbol>] the identity properties
|
10
|
-
attr_reader :identity_properties
|
11
|
-
|
12
9
|
def initialize
|
13
10
|
@collection = {}
|
14
11
|
@required_properties = []
|
15
|
-
@identity_properties = []
|
16
12
|
end
|
17
13
|
|
18
14
|
# Add a KeyMetadata to the store.
|
@@ -22,7 +18,6 @@ module LazyLazer
|
|
22
18
|
def add(key, meta)
|
23
19
|
@collection[key] = meta
|
24
20
|
@required_properties << key if meta.required?
|
25
|
-
@identity_properties << key if meta.identity?
|
26
21
|
meta
|
27
22
|
end
|
28
23
|
|
data/lib/lazy_lazer/version.rb
CHANGED
data/lib/lazy_lazer.rb
CHANGED
@@ -36,7 +36,6 @@ module LazyLazer
|
|
36
36
|
# @param options [Hash] the options to create the property with
|
37
37
|
# @option options [Boolean] :required (false) whether existence of this property should be
|
38
38
|
# checked on model creation
|
39
|
-
# @option options [Boolean] :identity (false) use this key for equality comparisions
|
40
39
|
# @option options [Boolean] :nil (false) shortcut for default: nil
|
41
40
|
# @option options [Object, Proc] :default the default value to return if not provided
|
42
41
|
# @option options [Symbol] :from (name) the key in the source object to get the property from
|
@@ -73,13 +72,13 @@ module LazyLazer
|
|
73
72
|
@_lazer_loaded = false
|
74
73
|
end
|
75
74
|
|
76
|
-
# Equality check.
|
75
|
+
# Equality check, performed using required keys.
|
77
76
|
# @param other [Object] the other object
|
78
77
|
# @return [Boolean]
|
79
78
|
def ==(other)
|
80
79
|
return false if self.class != other.class
|
81
|
-
return super if @_lazer_model.
|
82
|
-
@_lazer_model.
|
80
|
+
return super if @_lazer_model.required_properties.empty?
|
81
|
+
@_lazer_model.required_properties.each do |key_name|
|
83
82
|
return false if self[key_name] != other[key_name]
|
84
83
|
end
|
85
84
|
true
|