hyper-resource 1.0.0.lap52 → 1.0.0.lap53
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:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2fdb0a8d50f4f15b310d470b2e409627c2793c0512907b643b57919d204f58bb
         | 
| 4 | 
            +
              data.tar.gz: b61972174d030887f5d07b4a3a299f77ce0b7c816a97b4c882d18e26d9c28235
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3a4c12776795ea0c9cfbc88af0114e436b7b774fe7ddea644bbf06ef8d922721c8e5d290805c3bd148edcbda23c828c402a144a61eca4e6249ae68928bd2d0f1
         | 
| 7 | 
            +
              data.tar.gz: 3577ebf9be0425fad5d02e0a4151b3915b96cb037155c663c3a2f8333b1471f565d3fb494917d2f6e5fc2ebb1dac02be3ac531f86345a4adb179dbaacf203423
         | 
| @@ -326,7 +326,7 @@ module HyperRecord | |
| 326 326 | 
             
                      _notify_class_observers
         | 
| 327 327 | 
             
                      rest_methods[name][:result]
         | 
| 328 328 | 
             
                    end.fail do |response|
         | 
| 329 | 
            -
                      error_message = "#{self.to_s}.#{name}, a rest_method, failed to  | 
| 329 | 
            +
                      error_message = "#{self.to_s}.#{name}, a rest_method, failed to execute!"
         | 
| 330 330 | 
             
                      `console.error(error_message)`
         | 
| 331 331 | 
             
                      response
         | 
| 332 332 | 
             
                    end
         | 
| @@ -360,14 +360,14 @@ module HyperRecord | |
| 360 360 | 
             
                      _notify_observers
         | 
| 361 361 | 
             
                      @rest_methods_hash[name][:result]
         | 
| 362 362 | 
             
                    end.fail do |response|
         | 
| 363 | 
            -
                      error_message = "#{self.class.to_s}[#{self.id}].#{name}, a rest_method, failed to  | 
| 363 | 
            +
                      error_message = "#{self.class.to_s}[#{self.id}].#{name}, a rest_method, failed to execute!"
         | 
| 364 364 | 
             
                      `console.error(error_message)`
         | 
| 365 365 | 
             
                      response
         | 
| 366 366 | 
             
                    end
         | 
| 367 367 | 
             
                  end
         | 
| 368 368 | 
             
                  define_method(name) do |*args|
         | 
| 369 369 | 
             
                    _register_observer
         | 
| 370 | 
            -
                    if self.id && (@rest_methods_hash[name][:force] || !@rest_methods_hash[name].has_key?(:result))
         | 
| 370 | 
            +
                    if self.id && (self.class.rest_methods[name][:force] || @rest_methods_hash[name][:force] || !@rest_methods_hash[name].has_key?(:result))
         | 
| 371 371 | 
             
                      self.send("promise_#{name}", *args)
         | 
| 372 372 | 
             
                    end
         | 
| 373 373 | 
             
                    if @rest_methods_hash[name].has_key?(:result)
         | 
| @@ -0,0 +1,186 @@ | |
| 1 | 
            +
            module HyperRecord
         | 
| 2 | 
            +
              module PubSub
         | 
| 3 | 
            +
                def self.included(base)
         | 
| 4 | 
            +
                  base.extend(HyperRecord::PubSub::ClassMethods)
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                module ClassMethods
         | 
| 8 | 
            +
                  def _pusher_client
         | 
| 9 | 
            +
                    Hyperloop.pusher_instance ||= Pusher::Client.new(
         | 
| 10 | 
            +
                      app_id: Hyperloop.pusher[:app_id],
         | 
| 11 | 
            +
                      key: Hyperloop.pusher[:key],
         | 
| 12 | 
            +
                      secret: Hyperloop.pusher[:secret],
         | 
| 13 | 
            +
                      cluster: Hyperloop.pusher[:cluster]
         | 
| 14 | 
            +
                    )
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def publish_relation(base_record, relation_name, record = nil)
         | 
| 18 | 
            +
                    subscribers = Hyperloop.redis_instance.hgetall("HRPS__#{base_record.class}__#{base_record.id}__#{relation_name}")
         | 
| 19 | 
            +
                    time_now = Time.now.to_f
         | 
| 20 | 
            +
                    scrub_time = time_now - 24.hours.to_f
         | 
| 21 | 
            +
                    message = {
         | 
| 22 | 
            +
                      record_type: base_record.class.to_s,
         | 
| 23 | 
            +
                      id: base_record.id,
         | 
| 24 | 
            +
                      updated_at: base_record.updated_at,
         | 
| 25 | 
            +
                      relation: relation_name
         | 
| 26 | 
            +
                    }
         | 
| 27 | 
            +
                    if record
         | 
| 28 | 
            +
                      message[:cause] = {}
         | 
| 29 | 
            +
                      message[:cause][:record_type] = record.class.to_s
         | 
| 30 | 
            +
                      message[:cause][:id] = record.id
         | 
| 31 | 
            +
                      message[:cause][:updated_at] = record.updated_at
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
                    subscribers.each do |session_id, last_requested|
         | 
| 34 | 
            +
                      if last_requested.to_f < scrub_time
         | 
| 35 | 
            +
                        Hyperloop.redis_instance.hdel("HRPS__#{base_record.class}__#{base_record.id}__#{relation_name}", session_id)
         | 
| 36 | 
            +
                        next
         | 
| 37 | 
            +
                      end
         | 
| 38 | 
            +
                      if Hyperloop.resource_transport == :pusher
         | 
| 39 | 
            +
                        _pusher_client.trigger("hyper-record-update-channel-#{session_id}", 'update', message)
         | 
| 40 | 
            +
                      end
         | 
| 41 | 
            +
                    end
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  def publish_record(record)
         | 
| 45 | 
            +
                    subscribers = Hyperloop.redis_instance.hgetall("HRPS__#{record.class}__#{record.id}")
         | 
| 46 | 
            +
                    time_now = Time.now.to_f
         | 
| 47 | 
            +
                    scrub_time = time_now - 24.hours.to_f
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    message = {
         | 
| 50 | 
            +
                      record_type: record.class.to_s,
         | 
| 51 | 
            +
                      id: record.id,
         | 
| 52 | 
            +
                      updated_at: record.updated_at
         | 
| 53 | 
            +
                    }
         | 
| 54 | 
            +
                    message[:destroyed] = true if record.destroyed?
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    subscribers.each_slice(50) do |slice|
         | 
| 57 | 
            +
                      channel_array= []
         | 
| 58 | 
            +
                      slice.each do |session_id, last_requested|
         | 
| 59 | 
            +
                        if last_requested.to_f < scrub_time
         | 
| 60 | 
            +
                          Hyperloop.redis_instance.hdel("HRPS__#{record.class}__#{record.id}", session_id)
         | 
| 61 | 
            +
                          next
         | 
| 62 | 
            +
                        end
         | 
| 63 | 
            +
                        channel_array << "hyper-record-update-channel-#{session_id}"
         | 
| 64 | 
            +
                      end
         | 
| 65 | 
            +
                      if Hyperloop.resource_transport == :pusher && channel_array.size > 0
         | 
| 66 | 
            +
                        _pusher_client.trigger(channel_array, 'update', message)
         | 
| 67 | 
            +
                      end
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
                    Hyperloop.redis_instance.del("HRPS__#{record.class}__#{record.id}") if record.destroyed?
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  def publish_scope(record_class, scope_name)
         | 
| 73 | 
            +
                    subscribers = Hyperloop.redis_instance.hgetall("HRPS__#{record_class}__scope__#{scope_name}")
         | 
| 74 | 
            +
                    time_now = Time.now.to_f
         | 
| 75 | 
            +
                    scrub_time = time_now - 24.hours.to_f
         | 
| 76 | 
            +
                    subscribers.each do |session_id, last_requested|
         | 
| 77 | 
            +
                      if last_requested.to_f < scrub_time
         | 
| 78 | 
            +
                        Hyperloop.redis_instance.hdel("HRPS__#{record_class}__scope__#{scope_name}", session_id)
         | 
| 79 | 
            +
                        next
         | 
| 80 | 
            +
                      end
         | 
| 81 | 
            +
                      message = {
         | 
| 82 | 
            +
                        record_type: record_class.to_s,
         | 
| 83 | 
            +
                        scope: scope_name
         | 
| 84 | 
            +
                      }
         | 
| 85 | 
            +
                      if Hyperloop.resource_transport == :pusher
         | 
| 86 | 
            +
                        _pusher_client.trigger("hyper-record-update-channel-#{session_id}", 'update', message)
         | 
| 87 | 
            +
                      end
         | 
| 88 | 
            +
                    end
         | 
| 89 | 
            +
                  end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                  def subscribe_relation(relation, base_record = nil, relation_name = nil)
         | 
| 92 | 
            +
                    return unless session.id
         | 
| 93 | 
            +
                    time_now = Time.now.to_f.to_s
         | 
| 94 | 
            +
                    session_id = session.id.to_s
         | 
| 95 | 
            +
                    Hyperloop.redis_instance.pipelined do
         | 
| 96 | 
            +
                      if relation.is_a?(Enumerable)
         | 
| 97 | 
            +
                        # has_many
         | 
| 98 | 
            +
                        relation.each do |record|
         | 
| 99 | 
            +
                          Hyperloop.redis_instance.hset("HRPS__#{record.class}__#{record.id}", session_id, time_now)
         | 
| 100 | 
            +
                        end
         | 
| 101 | 
            +
                      elsif !relation.nil?
         | 
| 102 | 
            +
                        # has_one, belongs_to
         | 
| 103 | 
            +
                        Hyperloop.redis_instance.hset("HRPS__#{relation.class}__#{relation.id}", session_id, time_now)
         | 
| 104 | 
            +
                      end
         | 
| 105 | 
            +
                      Hyperloop.redis_instance.hset("HRPS__#{base_record.class}__#{base_record.id}__#{relation_name}", session_id, time_now) if base_record && relation_name
         | 
| 106 | 
            +
                    end
         | 
| 107 | 
            +
                  end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                  def subscribe_record(record)
         | 
| 110 | 
            +
                    return unless session.id
         | 
| 111 | 
            +
                    Hyperloop.redis_instance.hset "HRPS__#{record.class}__#{record.id}", session.id.to_s, Time.now.to_f.to_s
         | 
| 112 | 
            +
                  end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                  def subscribe_scope(collection, record_class = nil, scope_name = nil)
         | 
| 115 | 
            +
                    return unless session.id
         | 
| 116 | 
            +
                    time_now = Time.now.to_f.to_s
         | 
| 117 | 
            +
                    session_id = session.id.to_s
         | 
| 118 | 
            +
                    Hyperloop.redis_instance.pipelined do
         | 
| 119 | 
            +
                      if collection.is_a?(Enumerable)
         | 
| 120 | 
            +
                        collection.each do |record|
         | 
| 121 | 
            +
                          Hyperloop.redis_instance.hset("HRPS__#{record.class}__#{record.id}", session_id, time_now)
         | 
| 122 | 
            +
                        end
         | 
| 123 | 
            +
                      end
         | 
| 124 | 
            +
                      Hyperloop.redis_instance.hset("HRPS__#{record_class}__scope__#{scope_name}", session_id, time_now) if record_class && scope_name
         | 
| 125 | 
            +
                    end
         | 
| 126 | 
            +
                  end
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                  def pub_sub_relation(relation, base_record, relation_name, causing_record = nil)
         | 
| 129 | 
            +
                    subscribe_relation(relation, base_record, relation_name)
         | 
| 130 | 
            +
                    publish_relation(base_record, relation_name, causing_record)
         | 
| 131 | 
            +
                  end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                  def pub_sub_record(record)
         | 
| 134 | 
            +
                    subscribe_record(record)
         | 
| 135 | 
            +
                    publish_record(record)
         | 
| 136 | 
            +
                  end
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                  def pub_sub_scope(collection, record_class, scope_name)
         | 
| 139 | 
            +
                    subscribe_scope(collection, record_class, scope_name)
         | 
| 140 | 
            +
                    publish_scope(record_class, scope_name)
         | 
| 141 | 
            +
                  end
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                  def session
         | 
| 144 | 
            +
                    @_hyper_resource_session
         | 
| 145 | 
            +
                  end
         | 
| 146 | 
            +
                end
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                # instance methods
         | 
| 149 | 
            +
             | 
| 150 | 
            +
                def publish_relation(base_record, relation_name, record = nil)
         | 
| 151 | 
            +
                  self.class.publish_relation(base_record, relation_name, record)
         | 
| 152 | 
            +
                end
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                def publish_record(record)
         | 
| 155 | 
            +
                  self.class.publish_record(record)
         | 
| 156 | 
            +
                end
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                def publish_scope(record_class, scope_name)
         | 
| 159 | 
            +
                  self.class.publish_scope(record_class, scope_name)
         | 
| 160 | 
            +
                end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                def subscribe_relation(relation, base_record = nil, relation_name = nil)
         | 
| 163 | 
            +
                  self.class.subscribe_relation(relation, base_record, relation_name)
         | 
| 164 | 
            +
                end
         | 
| 165 | 
            +
             | 
| 166 | 
            +
                def subscribe_record(record)
         | 
| 167 | 
            +
                  self.class.subscribe_record(record)
         | 
| 168 | 
            +
                end
         | 
| 169 | 
            +
             | 
| 170 | 
            +
                def subscribe_scope(collection, record_class = nil, scope_name = nil)
         | 
| 171 | 
            +
                  self.class.subscribe_scope(collection, record_class, scope_name)
         | 
| 172 | 
            +
                end
         | 
| 173 | 
            +
             | 
| 174 | 
            +
                def pub_sub_relation(relation, base_record, relation_name, causing_record = nil)
         | 
| 175 | 
            +
                  self.class.pub_sub_relation(relation, base_record, relation_name, causing_record)
         | 
| 176 | 
            +
                end
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                def pub_sub_record(record)
         | 
| 179 | 
            +
                  self.class.pub_sub_record(record)
         | 
| 180 | 
            +
                end
         | 
| 181 | 
            +
             | 
| 182 | 
            +
                def pub_sub_scope(collection, record_class, scope_name)
         | 
| 183 | 
            +
                  self.class.pub_sub_scope(collection, record_class, scope_name)
         | 
| 184 | 
            +
                end
         | 
| 185 | 
            +
              end
         | 
| 186 | 
            +
            end
         | 
    
        data/lib/hyper_record.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: hyper-resource
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0.0. | 
| 4 | 
            +
              version: 1.0.0.lap53
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jan Biedermann
         | 
| @@ -208,6 +208,7 @@ files: | |
| 208 208 | 
             
            - lib/hyper_record/client_instance_methods.rb
         | 
| 209 209 | 
             
            - lib/hyper_record/collection.rb
         | 
| 210 210 | 
             
            - lib/hyper_record/dummy_value.rb
         | 
| 211 | 
            +
            - lib/hyper_record/pub_sub.rb
         | 
| 211 212 | 
             
            - lib/hyper_record/server_class_methods.rb
         | 
| 212 213 | 
             
            - lib/hyperloop/resource/client_drivers.rb
         | 
| 213 214 | 
             
            - lib/hyperloop/resource/config.rb
         |