vimo 0.1.0 → 0.1.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: 9beb8222f16151d7206ffc95d411d4fc938b0400ce600c4459f859c5033d9c11
4
- data.tar.gz: d71f8f015000aba75e62898fc0427eafbe8755365f1f5ba0c0ab50f670b402cb
3
+ metadata.gz: 165c7157085ad7675a72fcb99f22444322f0d235635e58103425a43eaab43da1
4
+ data.tar.gz: e54c776796bebdde6113a7d58e77afab59d5a4779dbed48df470c9b912f83707
5
5
  SHA512:
6
- metadata.gz: 843107fe2c31cd2e395143a7b3213e849a1101506f7b3fb3bed8f4d1a21370a1192334631b3ca7f2bb169dc8af69a2541d858ac4ec44d59b04efa1f9ddef2379
7
- data.tar.gz: 05f071ac5dd731b500d9d66c3a863d8491e3b00d23637b2b02caf43642eb3fbc01300ed385d179670d0f08ac4c59868ef23a8216ca92d3151e1f82ac8ae62f54
6
+ metadata.gz: 2ef13ba029adac1b3b17a3ac17c42df29f4ce1a1bc1bb693e0d73ebbc230ab4a805f4ee8f90092d014e963db06dbe8f9f145df6576430a9e6547ba7c1358f86c
7
+ data.tar.gz: 8b56cd796a0609b4305a759e93828d1b8fde8eabdf8e8d3b67bc3ed5f5ca0ca022c41d5226ffbfe6e2c0b14e9114b262e41505ad11a79f9a0b19c78606b67f9b
data/README.md CHANGED
@@ -117,7 +117,8 @@ users expand it.
117
117
  class Post < ApplicationRecord
118
118
  belongs_to :account
119
119
 
120
- extendable owner: :account
120
+ include Vimo::Expandable # OR add it to ApplicationRecord
121
+ expandable owner: :account
121
122
  end
122
123
  ```
123
124
 
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vimo
4
+ module Expandable
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+
9
+ def self.vimo_expand(options = {})
10
+ @@belongs_to_owner = options[:owner]
11
+
12
+ self.class_eval do
13
+
14
+ has_one :expanded, as: :expandable, class_name: "Vimo::Item"
15
+ delegate :data, to: :expanded
16
+
17
+ def vimo_owner
18
+ send(@@belongs_to_owner) if @@belongs_to_owner
19
+ end
20
+
21
+ def entities
22
+ if vimo_owner
23
+ vimo_owner.vimo_entities
24
+ else
25
+ Vimo::Entity
26
+ end
27
+ end
28
+
29
+ def expanded
30
+ super || build_expanded(entity: entities.find_or_create_by!(name: "_expand_#{self.class.table_name}"))
31
+ end
32
+
33
+ def entity_fields
34
+ @entity_fields ||= expanded.entity.fields
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -4,7 +4,7 @@ module Vimo
4
4
  class Item < ApplicationRecord
5
5
  serialize :data, JSON
6
6
  belongs_to :entity
7
- belongs_to :extendable, polymorphic: true, required: false
7
+ belongs_to :expandable, polymorphic: true, required: false
8
8
 
9
9
  validate :entity_definition
10
10
 
@@ -2,7 +2,7 @@ class CreateVimoItems < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  create_table :vimo_items do |t|
4
4
  t.references :entity, foreign_key: true
5
- t.references :extendable, polymorphic: true, index: true
5
+ t.references :expandable, polymorphic: true, index: true
6
6
  t.text :data
7
7
 
8
8
  t.timestamps
data/lib/vimo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vimo
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Galisteo
@@ -149,6 +149,7 @@ files:
149
149
  - app/mailers/vimo/application_mailer.rb
150
150
  - app/models/vimo/application_record.rb
151
151
  - app/models/vimo/entity.rb
152
+ - app/models/vimo/expandable.rb
152
153
  - app/models/vimo/field.rb
153
154
  - app/models/vimo/item.rb
154
155
  - app/models/vimo/system_name.rb