Class: Shep::TypeBox
- Inherits:
-
Object
show all
- Defined in:
- lib/shep/typeboxes.rb
Overview
Abstract base classes for all type boxes. All scalar subclasses may also hold nil.
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(field_desc) ⇒ TypeBox
Returns a new instance of TypeBox.
27
28
29
30
|
# File 'lib/shep/typeboxes.rb', line 27
def initialize(field_desc)
@desc = field_desc
@value = nil
end
|
Class Method Details
.to_yard_s ⇒ Object
Name for the Ruby type this holds as used by YARD. (This is part of making Entity self-documenting.)
39
|
# File 'lib/shep/typeboxes.rb', line 39
def self.to_yard_s = self.to_s.split(/::/)[-1].gsub(/Box$/, '')
|
Instance Method Details
#==(other) ⇒ Object
32
|
# File 'lib/shep/typeboxes.rb', line 32
def ==(other) = (other.class == self.class && other.get == @value)
|
#get ⇒ Object
50
|
# File 'lib/shep/typeboxes.rb', line 50
def get = @value
|
#get_for_json ⇒ Object
Set/Get in a format suitable for converting to JSON.
53
|
# File 'lib/shep/typeboxes.rb', line 53
def get_for_json = @value
|
#inspect ⇒ Object
35
|
# File 'lib/shep/typeboxes.rb', line 35
def inspect = to_s
|
#set(newval) ⇒ Object
Assignment from Ruby types with a type check.
42
43
44
45
|
# File 'lib/shep/typeboxes.rb', line 42
def set(newval)
check(newval) unless newval == nil
@value = newval
end
|
#set? ⇒ Boolean
48
|
# File 'lib/shep/typeboxes.rb', line 48
def set? = !unset?
|
#set_from_json(newval) ⇒ Object
54
|
# File 'lib/shep/typeboxes.rb', line 54
def set_from_json(newval) = set(newval)
|
#to_s ⇒ Object
34
|
# File 'lib/shep/typeboxes.rb', line 34
def to_s = "#{self.class}(#{@value})"
|
#unset? ⇒ Boolean
47
|
# File 'lib/shep/typeboxes.rb', line 47
def unset? = (@value == nil)
|