card-mod-virtual 0.13.2 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df938a392274da66b29fa013e04706a896c13009c81a7c3966441c7e5e5e36bf
4
- data.tar.gz: 3db3c3eb34257e72bff48007d3bd802567598eaa5c54e7a0bdc12fecb1ca2a1d
3
+ metadata.gz: 1faaea40397c0d5da4eb68f26af697f89f80c38f26185988cac81f01eb0cc938
4
+ data.tar.gz: 1a5e126f6857daff50088c18e6401b5d9d56c831b4c0b1da56cd0d0b05db6419
5
5
  SHA512:
6
- metadata.gz: 8b50175982636d3d4679d66ff1841b03a5eb5da1bb62ec19bfb748f073832453d0d9d53f3524a64a60f26a6cabe466ef8029d0c3470346707fa1fc0bfe07c951
7
- data.tar.gz: 287b8c010c3a05550e6f846be7dd191c37a362573ff07ca6e0eca7a594421d44e6601f18e4a9a7a33a5902f17a121e21ea06935d512f1fd0ec6cdbb179ac992a
6
+ metadata.gz: 1c76342d146a4fc7d1c17c20b42716971c84f23111b8939d15770041f0f367c463444033f6654a0dcbcdbd8a0ab2755c7e9b586325d6123be082efc3728f6963
7
+ data.tar.gz: 8d959e2aa0ce142094980c4cdb1abe6a7f2b2df503a4039129b9c41095cb6d0582055f454826e5a574849a4bfc84f02ce90ba275bce8ede271bc77905c4949ec
data/lib/card/virtual.rb CHANGED
@@ -6,53 +6,44 @@ class Card
6
6
  # the card_virtuals table.
7
7
  class Virtual < Cardio::Record
8
8
  def update new_content
9
- update! content: new_content
9
+ content == new_content ? touch : update!(content: new_content)
10
10
  new_content
11
11
  end
12
12
 
13
13
  class << self
14
- def create card, virtual_content=nil
15
- validate_card card
16
- virtual_content ||= block_given? ? yield : card.generate_virtual_content
17
- create! left_id: left_id(card),
18
- right_id: right_id(card),
19
- left_key: card.name.left_key,
20
- content: virtual_content
21
- end
22
-
23
- def create_or_update card, virtual_content
24
- if (virtual_card = find_by_card(card))
25
- virtual_card.update virtual_content
26
- else
27
- create card, virtual_content
14
+ def fetch card
15
+ cache.fetch card.key do
16
+ find_by_card(card) || create(card)
28
17
  end
29
18
  end
30
19
 
31
- def fetch_content card, &block
32
- find_content_by_card(card) || create(card, &block).content
20
+ def save card
21
+ virt = find_by_card card
22
+ virt ? virt.update(card.virtual_content) : create(card)
33
23
  end
34
24
 
35
- def fetch card, &block
36
- find_by_card(card) || create(card, &block)
25
+ def delete card
26
+ find_by_card(card)&.delete
37
27
  end
38
28
 
39
- def refresh card
40
- virtual = find_by_card(card)
41
- return create(card) unless virtual
29
+ private
42
30
 
43
- virtual.update card.generate_virtual_content
31
+ def cache
32
+ Card::Cache[Virtual]
44
33
  end
45
34
 
46
- def find_content_by_card card
47
- where_card(card)&.pluck(:content)&.first
35
+ def create card
36
+ validate_card card
37
+ create! left_id: left_id(card),
38
+ right_id: right_id(card),
39
+ left_key: card.name.left_key,
40
+ content: card.virtual_content
48
41
  end
49
42
 
50
43
  def find_by_card card
51
44
  where_card(card).take
52
45
  end
53
46
 
54
- private
55
-
56
47
  def where_card card
57
48
  query = { right_id: right_id(card) }
58
49
  if (lid = left_id(card))
@@ -4,32 +4,40 @@ def virtual?
4
4
  new?
5
5
  end
6
6
 
7
- def history?
8
- false
9
- end
10
-
11
- def followable?
12
- false
7
+ # the content to be cached
8
+ # (can be overridden)
9
+ def virtual_content
10
+ attributes["db_content"]
13
11
  end
14
12
 
15
13
  def db_content
16
- Card::Virtual.fetch_content(self)
14
+ Virtual.fetch(self)&.content
17
15
  end
18
16
 
19
- # called to refresh the virtual content
20
- # the default way is to use the card's template content
21
- def generate_virtual_content
22
- template&.db_content
17
+ def updated_at
18
+ Virtual.fetch(self)&.updated_at
23
19
  end
24
20
 
25
- event :save_virtual_content, :prepare_to_store, on: :save, changed: :content do
26
- Card::Virtual.create_or_update(self, attributes["db_content"])
21
+ event :save_virtual_content, :prepare_to_store, on: :save do
22
+ Virtual.save self
27
23
  abort :success
28
24
  end
29
25
 
30
26
  event :delete_virtual_content, :prepare_to_store, on: :delete do
31
- Card::Virtual.find_by_card(self)&.delete
32
- abort :success
27
+ Virtual.delete self
28
+ abort :success unless real?
29
+ end
30
+
31
+ # TODO: confirm that the following are needed (and if so, explain why)
32
+ # in theory, if we always abort, we'll never trigger history/follow events,
33
+ # and we'll never have a card to delete, no?
34
+
35
+ def history?
36
+ false
37
+ end
38
+
39
+ def followable?
40
+ false
33
41
  end
34
42
 
35
43
  def delete
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-virtual
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-08-06 00:00:00.000000000 Z
13
+ date: 2022-01-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.103.2
21
+ version: 1.104.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.103.2
28
+ version: 1.104.1
29
29
  description: ''
30
30
  email:
31
31
  - info@decko.org
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.1.6
63
+ rubygems_version: 3.2.15
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: virtual