Class: RiceBubble::Attributes::Any

Inherits:
Base
  • Object
show all
Defined in:
lib/rice_bubble/attributes/any.rb

Direct Known Subclasses

Enum

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#fetch, #optional, #valid_types

Constructor Details

#initialize(*members) ⇒ Any

Returns a new instance of Any.



6
7
8
9
# File 'lib/rice_bubble/attributes/any.rb', line 6

def initialize(*members, &)
  super(&)
  @members = members.flatten
end

Instance Attribute Details

#membersObject (readonly)

Returns the value of attribute members.



4
5
6
# File 'lib/rice_bubble/attributes/any.rb', line 4

def members
  @members
end

Instance Method Details

#call(value, path: '') ⇒ Object



15
16
17
# File 'lib/rice_bubble/attributes/any.rb', line 15

def call(value, path: '')
  super(which(value)&.call(value, path:) || value, path:)
end

#descriptionObject



23
24
25
# File 'lib/rice_bubble/attributes/any.rb', line 23

def description
  "one of [#{members.map(&:description).join(", ")}]"
end

#valid?(value) ⇒ Boolean

Returns:



11
12
13
# File 'lib/rice_bubble/attributes/any.rb', line 11

def valid?(value)
  !which(value).nil?
end

#which(value) ⇒ Object



19
20
21
# File 'lib/rice_bubble/attributes/any.rb', line 19

def which(value)
  members.find { |member| member.valid?(value) }
end