Sha256: 2d307e83aa6a8c5cd30b3df025826a5225830b2f3b5ca0417984c343dfcb9a10

Contents?: true

Size: 627 Bytes

Versions: 36

Compression:

Stored size: 627 Bytes

Contents

module Refine
  module Stabilizers
    class DatabaseStabilizer

      def to_stable_id(filter:, name: nil)
        # Serialize the filter class and blueprint. Reference via id.
        model.find_or_create_by!(state: filter.state, name: name).id
      end

      def from_stable_id(id:, initial_query: nil)
        # Find the associated StoredFilter by id and return state. Decode to create blueprint
        state = ActiveSupport::JSON.decode(model.find(id).state).deep_symbolize_keys
        Refine::Filter.from_state(state, initial_query)
      end

      def model
        Refine::StoredFilter
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
refine-rails-2.13.3 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.13.2 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.13.1 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.13.0 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.12.2 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.12.1 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.12.0 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.12 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.11 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.10 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.9 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.8 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.6 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.5 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.4 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.3 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.2 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.1 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.11.0 app/models/refine/stabilizers/database_stabilizer.rb
refine-rails-2.10.1 app/models/refine/stabilizers/database_stabilizer.rb