Sha256: b3246946996160608e9fd0820ad659075d40a9b6d3e7329d602da99464d0e711

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module Configurable
  module ConfigTypes
    class ObjectType
      class << self
        attr_reader :matchers
      
        def inherited(base) # :nodoc:
          unless base.instance_variable_defined?(:@matchers)
            base.instance_variable_set(:@matchers, matchers.dup)
          end
        end
        
        def subclass(*matchers, &caster)
          subclass = Class.new(self)
          subclass.matches(*matchers)
          subclass.cast(&caster)
          subclass
        end
      
        def cast(&block)
          define_method(:cast, &block) if block
          self
        end
      
        def uncast(&block)
          define_method(:uncast, &block) if block
          self
        end
      
        def errors(&block)
          define_method(:errors, &block) if block
          self
        end
      
        def matches(*matchers)
          @matchers = matchers
          self
        end
      
        def matches?(value)
          matchers.any? {|matcher| matcher === value }
        end
      end
      matches()
      
      def initialize(attrs={})
      end
      
      def cast(input)
        input
      end
      
      def uncast(value)
        value
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
configurable-1.0.0 lib/configurable/config_types/object_type.rb