Class: Configurable::ConfigTypes::ObjectType

Inherits:
Object
  • Object
show all
Defined in:
lib/configurable/config_types/object_type.rb

Direct Known Subclasses

BooleanType, FloatType, IntegerType, NestType, StringType

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ ObjectType

Returns a new instance of ObjectType.



46
47
# File 'lib/configurable/config_types/object_type.rb', line 46

def initialize(attrs={})
end

Class Attribute Details

.matchersObject (readonly)

Returns the value of attribute matchers.



5
6
7
# File 'lib/configurable/config_types/object_type.rb', line 5

def matchers
  @matchers
end

Class Method Details

.cast(&block) ⇒ Object



20
21
22
23
# File 'lib/configurable/config_types/object_type.rb', line 20

def cast(&block)
  define_method(:cast, &block) if block
  self
end

.errors(&block) ⇒ Object



30
31
32
33
# File 'lib/configurable/config_types/object_type.rb', line 30

def errors(&block)
  define_method(:errors, &block) if block
  self
end

.inherited(base) ⇒ Object

:nodoc:



7
8
9
10
11
# File 'lib/configurable/config_types/object_type.rb', line 7

def inherited(base) # :nodoc:
  unless base.instance_variable_defined?(:@matchers)
    base.instance_variable_set(:@matchers, matchers.dup)
  end
end

.matches(*matchers) ⇒ Object



35
36
37
38
# File 'lib/configurable/config_types/object_type.rb', line 35

def matches(*matchers)
  @matchers = matchers
  self
end

.matches?(value) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/configurable/config_types/object_type.rb', line 40

def matches?(value)
  matchers.any? {|matcher| matcher === value }
end

.subclass(*matchers, &caster) ⇒ Object



13
14
15
16
17
18
# File 'lib/configurable/config_types/object_type.rb', line 13

def subclass(*matchers, &caster)
  subclass = Class.new(self)
  subclass.matches(*matchers)
  subclass.cast(&caster)
  subclass
end

.uncast(&block) ⇒ Object



25
26
27
28
# File 'lib/configurable/config_types/object_type.rb', line 25

def uncast(&block)
  define_method(:uncast, &block) if block
  self
end

Instance Method Details

#cast(input) ⇒ Object



49
50
51
# File 'lib/configurable/config_types/object_type.rb', line 49

def cast(input)
  input
end

#uncast(value) ⇒ Object



53
54
55
# File 'lib/configurable/config_types/object_type.rb', line 53

def uncast(value)
  value
end