Sha256: 2d548152205774bf3ed3cec7ba6871b68bf8ecba9b5ca156f6f60fb8864d5f4c
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
module Parametric module Policies class Policy def initialize(value, options, decorated = nil) @value, @options = value, options @decorated = decorated end def wrap(decoratedClass) decoratedClass.new(@value, @options, self) end def value Array(@value) end protected attr_reader :decorated, :options end class DefaultPolicy < Policy def value v = decorated.value v.any? ? v : Array(options[:default]) end end class MultiplePolicy < Policy OPTION_SEPARATOR = /\s*,\s*/.freeze def value decorated.value.map do |v| v.is_a?(String) ? v.split(options.fetch(:separator, OPTION_SEPARATOR)) : v end.flatten end end class SinglePolicy < Policy def value decorated.value.first end end class OptionsPolicy < Policy def value decorated.value.each_with_object([]){|a,arr| arr << a if options[:options].include?(a) } end end class MatchPolicy < Policy def value decorated.value.each_with_object([]){|a,arr| arr << a if a.to_s =~ options[:match] } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
parametric-0.0.2 | lib/parametric/policies.rb |