vimo 0.1.1 → 0.1.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 +12 -7
- data/app/controllers/vimo/items_controller.rb +1 -1
- data/app/models/vimo/item.rb +12 -14
- data/db/migrate/20180208181633_create_vimo_entities.rb +1 -0
- data/db/migrate/20180210104430_create_vimo_items.rb +1 -1
- data/lib/vimo.rb +2 -0
- data/{app/models → lib}/vimo/expandable.rb +8 -6
- data/lib/vimo/ownerable.rb +17 -0
- data/lib/vimo/version.rb +1 -1
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1005a992604203884f06ec2f60da43f3b990814d981f18fd53e340f68cdfddb9
         | 
| 4 | 
            +
              data.tar.gz: 17a6dcf1e5b2f2e702d9e107cdf4eacb9e4aa5e421f92fb4874487d92643ccd1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 43b32c3e3268e1cdf280cde01ce20c9489b05db23d8ed400ab44a5e68c39b9432437d56a71e74e548d85f4e341605e7d93b61dcd71ba5fbd45e655867b3c09b0
         | 
| 7 | 
            +
              data.tar.gz: a5ce59a8456d87afa1759455785035568d847e333077a2e56a3d4bad79b02cd5b4143cecc9ed62c857f4fac1b5bb5dceca98b2dabbe6bb636d1166751790d028
         | 
    
        data/README.md
    CHANGED
    
    | @@ -5,7 +5,7 @@ Rails engine that allow to your users create and customize their own virtual mod | |
| 5 5 | 
             
            ## Warning
         | 
| 6 6 |  | 
| 7 7 | 
             
            This engine is in a very early stage and the DSL and APIs could change, if you
         | 
| 8 | 
            -
            are  | 
| 8 | 
            +
            are interested on use it you can emailme: `ceritium@gmail.com`.
         | 
| 9 9 |  | 
| 10 10 | 
             
            ## Installation
         | 
| 11 11 |  | 
| @@ -75,7 +75,7 @@ DELETE /vimo/entities/:entity/items/:id | |
| 75 75 |  | 
| 76 76 | 
             
            Create an item curl example:
         | 
| 77 77 | 
             
            ```
         | 
| 78 | 
            -
            curl localhost:3000/vimo/entities/comments/items -X POST -H 'Content-Type: application/json' -d '{"title": "a title"}'
         | 
| 78 | 
            +
            curl localhost:3000/vimo/entities/comments/items -X POST -H 'Content-Type: application/json' -d '{"item" : {"title": "a title"}}'
         | 
| 79 79 | 
             
            ```
         | 
| 80 80 |  | 
| 81 81 | 
             
            Short path version
         | 
| @@ -107,6 +107,14 @@ end | |
| 107 107 |  | 
| 108 108 | 
             
            Setting a `owner` scope the uniquenes constraints.
         | 
| 109 109 |  | 
| 110 | 
            +
            The owner should respond to `vimo_entities`
         | 
| 111 | 
            +
             | 
| 112 | 
            +
            ```ruby
         | 
| 113 | 
            +
            class Account < ApplicationRecord
         | 
| 114 | 
            +
              vimo_owner
         | 
| 115 | 
            +
            end
         | 
| 116 | 
            +
            ```
         | 
| 117 | 
            +
             | 
| 110 118 |  | 
| 111 119 | 
             
            ### Expand your models
         | 
| 112 120 |  | 
| @@ -117,15 +125,12 @@ users expand it. | |
| 117 125 | 
             
            class Post < ApplicationRecord
         | 
| 118 126 | 
             
              belongs_to :account
         | 
| 119 127 |  | 
| 120 | 
            -
               | 
| 121 | 
            -
              expandable owner: :account
         | 
| 128 | 
            +
              vimo_expand owner: :account
         | 
| 122 129 | 
             
            end
         | 
| 123 130 | 
             
            ```
         | 
| 124 131 |  | 
| 125 | 
            -
            Now can manage the virtual attributes of the model `Post` with the identifier ` | 
| 126 | 
            -
             | 
| 132 | 
            +
            Now can manage the virtual attributes of the model `Post` with the identifier `_expand_posts`.
         | 
| 127 133 |  | 
| 128 | 
            -
            WIP
         | 
| 129 134 |  | 
| 130 135 | 
             
            ## Contributing
         | 
| 131 136 | 
             
            Contribution directions go here.
         | 
    
        data/app/models/vimo/item.rb
    CHANGED
    
    | @@ -7,6 +7,9 @@ module Vimo | |
| 7 7 | 
             
                belongs_to :expandable, polymorphic: true, required: false
         | 
| 8 8 |  | 
| 9 9 | 
             
                validate :entity_definition
         | 
| 10 | 
            +
                validate :expanded
         | 
| 11 | 
            +
                validates :expandable_id, uniqueness: { scope: :expandable_type },
         | 
| 12 | 
            +
                  allow_nil: true
         | 
| 10 13 |  | 
| 11 14 | 
             
                class << self
         | 
| 12 15 | 
             
                  def parse(value_o, kind)
         | 
| @@ -43,26 +46,21 @@ module Vimo | |
| 43 46 | 
             
                  ({ id: id }).merge(data)
         | 
| 44 47 | 
             
                end
         | 
| 45 48 |  | 
| 46 | 
            -
                 | 
| 47 | 
            -
                  self.data ||= {}
         | 
| 48 | 
            -
                  self.data = entity.fields.inject(self.data) do |memo, field|
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                    name = field.name.to_s
         | 
| 51 | 
            -
                    kind = field.kind.to_s
         | 
| 49 | 
            +
                private
         | 
| 52 50 |  | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 51 | 
            +
                def expanded
         | 
| 52 | 
            +
                  if entity.expand_model.present?
         | 
| 53 | 
            +
                    if expandable.present?
         | 
| 54 | 
            +
                      unless expandable.model_name.name == entity.expand_model
         | 
| 55 | 
            +
                        errors.add(:expandable, "is invalid")
         | 
| 56 | 
            +
                      end
         | 
| 57 | 
            +
                    else
         | 
| 58 | 
            +
                      errors.add(:expandable, "is required")
         | 
| 56 59 | 
             
                    end
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                    memo
         | 
| 59 60 | 
             
                  end
         | 
| 60 61 | 
             
                end
         | 
| 61 62 |  | 
| 62 | 
            -
                private
         | 
| 63 | 
            -
             | 
| 64 63 | 
             
                def entity_definition
         | 
| 65 | 
            -
                  self.data ||= {}
         | 
| 66 64 | 
             
                  entity.fields.each do |field|
         | 
| 67 65 | 
             
                    name = field.name.to_s
         | 
| 68 66 | 
             
                    if field.required
         | 
| @@ -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 :expandable, polymorphic: true, index: true
         | 
| 5 | 
            +
                  t.references :expandable, polymorphic: true, index: { unique: true }
         | 
| 6 6 | 
             
                  t.text :data
         | 
| 7 7 |  | 
| 8 8 | 
             
                  t.timestamps
         | 
    
        data/lib/vimo.rb
    CHANGED
    
    
| @@ -7,15 +7,15 @@ module Vimo | |
| 7 7 | 
             
                included do
         | 
| 8 8 |  | 
| 9 9 | 
             
                  def self.vimo_expand(options = {})
         | 
| 10 | 
            -
                     | 
| 10 | 
            +
                    @belongs_to_owner = options[:owner]
         | 
| 11 | 
            +
                    data_method = options[:data_method] || "data"
         | 
| 11 12 |  | 
| 12 13 | 
             
                    self.class_eval do
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                       | 
| 15 | 
            -
                      delegate :data, to: :expanded
         | 
| 14 | 
            +
                      has_one :expanded, as: :expandable, class_name: "Vimo::Item", autosave: true
         | 
| 15 | 
            +
                      delegate data_method, "#{data_method}=", to: :expanded
         | 
| 16 16 |  | 
| 17 17 | 
             
                      def vimo_owner
         | 
| 18 | 
            -
                        send( | 
| 18 | 
            +
                        send(@belongs_to_owner) if @belongs_to_owner
         | 
| 19 19 | 
             
                      end
         | 
| 20 20 |  | 
| 21 21 | 
             
                      def entities
         | 
| @@ -27,7 +27,7 @@ module Vimo | |
| 27 27 | 
             
                      end
         | 
| 28 28 |  | 
| 29 29 | 
             
                      def expanded
         | 
| 30 | 
            -
                        super || build_expanded(entity: entities.find_or_create_by!(name: "_expand_#{self.class.table_name}"))
         | 
| 30 | 
            +
                        super || build_expanded(entity: entities.find_or_create_by!(name: "_expand_#{self.class.table_name}", expand_model: self.model_name.name))
         | 
| 31 31 | 
             
                      end
         | 
| 32 32 |  | 
| 33 33 | 
             
                      def entity_fields
         | 
| @@ -38,3 +38,5 @@ module Vimo | |
| 38 38 | 
             
                end
         | 
| 39 39 | 
             
              end
         | 
| 40 40 | 
             
            end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            ActiveRecord::Base.send :include, Vimo::Expandable
         | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Vimo
         | 
| 4 | 
            +
              module Ownerable
         | 
| 5 | 
            +
                extend ActiveSupport::Concern
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                included do
         | 
| 8 | 
            +
                  def self.vimo_owner(options = {})
         | 
| 9 | 
            +
                    self.class_eval do
         | 
| 10 | 
            +
                      has_many :vimo_entities, class_name: "Vimo::Entity", as: :owner
         | 
| 11 | 
            +
                    end
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ActiveRecord::Base.send :include, Vimo::Ownerable
         | 
    
        data/lib/vimo/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: vimo
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jose Galisteo
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2018-02- | 
| 11 | 
            +
            date: 2018-02-20 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: kaminari
         | 
| @@ -149,7 +149,6 @@ 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
         | 
| 153 152 | 
             
            - app/models/vimo/field.rb
         | 
| 154 153 | 
             
            - app/models/vimo/item.rb
         | 
| 155 154 | 
             
            - app/models/vimo/system_name.rb
         | 
| @@ -166,6 +165,8 @@ files: | |
| 166 165 | 
             
            - lib/vimo.rb
         | 
| 167 166 | 
             
            - lib/vimo/configuration.rb
         | 
| 168 167 | 
             
            - lib/vimo/engine.rb
         | 
| 168 | 
            +
            - lib/vimo/expandable.rb
         | 
| 169 | 
            +
            - lib/vimo/ownerable.rb
         | 
| 169 170 | 
             
            - lib/vimo/version.rb
         | 
| 170 171 | 
             
            homepage: https://github.com/ceritium/vimo
         | 
| 171 172 | 
             
            licenses:
         |