Sha256: 0eed31bb580c6d4514ddc5641e39c3b949f22fc5b9c102d896865dd922872140

Contents?: true

Size: 954 Bytes

Versions: 3

Compression:

Stored size: 954 Bytes

Contents

module BrowsingHistory::Storages
  IOMethods = %i(fetch add update clear count interface).freeze

  class NotOverideError < BrowsingHistory::Error; end

  class Base
    attr_accessor :browser, :historizable, :options

    def initialize(browser, historizable)
      @browser      = browser
      @historizable = historizable
    end

    def method_missing(method, *args)
      if method.in?(IOMethods)
        raise NotOverideError
      else
        super
      end
    end

    class << self
      def connect
        IOMethods.each do |method|
          define_singleton_method(method) do |browser, historizable, *_args|
            opts = _args.dup.extract_options!.merge(default_options)
            new(browser, historizable).send(method, **opts)
          end
        end
      end

      def default_options
        {}
      end
    end
  end

  require 'browsing_history/storages/redis'
  require 'browsing_history/storages/active_record'
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
browsing_history-0.0.4 lib/browsing_history/storages/base.rb
browsing_history-0.0.3 lib/browsing_history/storages/base.rb
browsing_history-0.0.2 lib/browsing_history/storages/base.rb