Sha256: 5ebacd5dbc126262adb9fa8c0d9ad868aec8f056c1a2b2f66c0c7e70392fc03d
Contents?: true
Size: 687 Bytes
Versions: 2
Compression:
Stored size: 687 Bytes
Contents
# frozen_string_literal: true module TinyFilter class Base class << self def filters(key, &block) key = key.to_sym raise AlreadyDefinedError, "filter :#{key} defined more than once in #{self}" if __filters__.key?(key) __filters__[key] = block end def filter(base_scope, args = {}) args.inject(base_scope) do |scope, (key, value)| key = key.to_sym raise NotDefinedError, "unable to find filter :#{key} in #{self}" unless __filters__.key?(key) __filters__[key].call(scope, value) end end private def __filters__ @__filters__ ||= {} end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tiny_filter-0.1.1 | lib/tiny_filter/base.rb |
tiny_filter-0.1.0 | lib/tiny_filter/base.rb |