jason-rails 0.6.0 → 0.6.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/client/package.json +1 -1
- data/lib/jason.rb +35 -8
- data/lib/jason/publisher.rb +4 -0
- data/lib/jason/subscription.rb +0 -2
- data/lib/jason/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a641c2277ccd7336d71cb79cd3f65710ebb0078db5cef102441d9c3fc2e6102d
         | 
| 4 | 
            +
              data.tar.gz: 467d4fff10d1f4c9a1ee847e409d4b8cc3ab8f8a7a0e93e9404fe275a35a3e47
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 606d1919bfe6c512e98a565619662b23f76f639da7ce55defafef7ced5b2e0112af8e4d61e63aa00b6335803faaaa6b863d621a114259ca5998c574d4ed5d59b
         | 
| 7 | 
            +
              data.tar.gz: a4f1c02c5c8c6a14fc6aa128b55ebc25ba54e2293561dd335dd87bb75b49e32df7af9434186f247efee6b81e16dae59e02d56a87f696ef8b217a01f167ac9f8c
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -142,6 +142,7 @@ Development is primarily driven by the needs of projects we're using Jason in. I | |
| 142 142 | 
             
            - Failure handling - rolling back local state in case of an error on the server
         | 
| 143 143 | 
             
            - Authorization - more thorough authorization integration, with utility functions for common authorizations. Allowing authorization of access to particular fields such as restricting the fields of a user that are publicly broadcast.
         | 
| 144 144 | 
             
            - Utilities for "Draft editing" - both storing client-side copies of model trees which can be committed or discarded, as well as persisting a shadow copy to the database (to allow resumable editing, or possibly collaborative editing features)
         | 
| 145 | 
            +
            - Benchmark and migrate if necessary ConnectionPool::Wrapper vs ConnectionPool
         | 
| 145 146 |  | 
| 146 147 | 
             
            ## Development
         | 
| 147 148 |  | 
    
        data/client/package.json
    CHANGED
    
    
    
        data/lib/jason.rb
    CHANGED
    
    | @@ -30,20 +30,47 @@ module Jason | |
| 30 30 | 
             
              self.pusher_region = 'eu'
         | 
| 31 31 | 
             
              self.pusher_channel_prefix = 'jason'
         | 
| 32 32 |  | 
| 33 | 
            -
               | 
| 33 | 
            +
              def self.init
         | 
| 34 | 
            +
                # Check if the schema has changed since last time app was started. If so, do some work to ensure cache contains the correct data
         | 
| 35 | 
            +
                got_lock = $redis_jason.set('jason:schema:lock', nx: true, ex: 3600) # Basic lock mechanism for multi-process environments
         | 
| 36 | 
            +
                return if !got_lock
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                previous_schema = JSON.parse($redis_jason.get('jason:last_schema') || '{}')
         | 
| 39 | 
            +
                current_schema = Jason.schema.deep_stringify_keys.deep_transform_values { |v| v.is_a?(Symbol) ? v.to_s : v }
         | 
| 40 | 
            +
                pp current_schema
         | 
| 41 | 
            +
                current_schema.each do |model, config|
         | 
| 42 | 
            +
                  if config != previous_schema[model]
         | 
| 43 | 
            +
                    puts "Config changed for #{model}"
         | 
| 44 | 
            +
                    puts "Old config was #{previous_schema[model]}"
         | 
| 45 | 
            +
                    puts "New config is #{config}"
         | 
| 46 | 
            +
                    puts "Rebuilding cache for #{model}"
         | 
| 47 | 
            +
                    model.classify.constantize.cache_all
         | 
| 48 | 
            +
                    puts "Done"
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                $redis_jason.set('jason:last_schema', current_schema.to_json)
         | 
| 53 | 
            +
              ensure
         | 
| 54 | 
            +
                $redis_jason.del('jason:schema:lock')
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                previous_config = 'test'
         | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
             | 
| 34 59 |  | 
| 35 60 | 
             
              # this function maps the vars from your app into your engine
         | 
| 36 61 | 
             
              def self.setup(&block)
         | 
| 37 62 | 
             
                yield self
         | 
| 38 | 
            -
              end
         | 
| 39 63 |  | 
| 40 | 
            -
             | 
| 64 | 
            +
                $redis_jason = self.redis || ::ConnectionPool::Wrapper.new(size: 5, timeout: 3) { ::Redis.new(url: ENV['REDIS_URL']) }
         | 
| 41 65 |  | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 66 | 
            +
                if ![:action_cable, :pusher].include?(self.transport_service)
         | 
| 67 | 
            +
                  raise "Unknown transport service '#{self.transport_service}' specified"
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                if self.transport_service == :pusher && self.pusher.blank?
         | 
| 71 | 
            +
                  raise "Pusher specified as transport service but no Pusher client provided. Please configure with config.pusher = Pusher::Client.new(...)"
         | 
| 72 | 
            +
                end
         | 
| 45 73 |  | 
| 46 | 
            -
             | 
| 47 | 
            -
                raise "Pusher specified as transport service but no Pusher client provided. Please configure with config.pusher = Pusher::Client.new(...)"
         | 
| 74 | 
            +
                init
         | 
| 48 75 | 
             
              end
         | 
| 49 76 | 
             
            end
         | 
    
        data/lib/jason/publisher.rb
    CHANGED
    
    | @@ -91,6 +91,10 @@ module Jason::Publisher | |
| 91 91 | 
             
                Jason::Subscription.for_instance(self.class.name.underscore, id)
         | 
| 92 92 | 
             
              end
         | 
| 93 93 |  | 
| 94 | 
            +
              def jason_cached_value
         | 
| 95 | 
            +
                JSON.parse($redis_jason.hget("jason:cache:#{self.class.name.underscore}", id) || '{}')
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
             | 
| 94 98 | 
             
              class_methods do
         | 
| 95 99 | 
             
                def cache_all
         | 
| 96 100 | 
             
                  all.each(&:cache_json)
         | 
    
        data/lib/jason/subscription.rb
    CHANGED
    
    | @@ -362,8 +362,6 @@ class Jason::Subscription | |
| 362 362 | 
             
                  instance_jsons, idx = Jason::LuaGenerator.new.get_payload(model_name, id)
         | 
| 363 363 | 
             
                end
         | 
| 364 364 |  | 
| 365 | 
            -
                return if instance_jsons.blank?
         | 
| 366 | 
            -
             | 
| 367 365 | 
             
                payload = instance_jsons.map do |instance_json|
         | 
| 368 366 | 
             
                  instance_json ? JSON.parse(instance_json) : {}
         | 
| 369 367 | 
             
                end
         | 
    
        data/lib/jason/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: jason-rails
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.6. | 
| 4 | 
            +
              version: 0.6.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - James Rees
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2021-02- | 
| 11 | 
            +
            date: 2021-02-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |