Sha256: c1c512774fe9f23d999fbccb31729be9af9e5578bca82cf92ba8a96370ea5a8a

Contents?: true

Size: 674 Bytes

Versions: 2

Compression:

Stored size: 674 Bytes

Contents

# frozen_string_literal: true
module CheeseCloth
  class Wrapper
    attr_reader :klass, :filter_list, :scope, :default_scope_proc

    def initialize(klass)
      @klass = klass
      @filter_list = FilterList.new(klass)
    end

    def assign_default_scope_proc(block)
      @default_scope_proc = block
    end

    def prepare_and_run(instance)
      assign_and_check_scope(instance)
      run(instance)
    end

    def assign_and_check_scope(instance)
      @scope ||= default_scope_proc && default_scope_proc.call
      raise MissingScopeError, self.class unless instance.scope
    end

    def run(instance)
      filter_list.run_filters(instance)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cheesecloth-0.1.1 lib/cheesecloth/wrapper.rb
cheesecloth-0.1.0 lib/cheesecloth/wrapper.rb