module Structured::Struct
Constants
- Boolean
Alias these types here so these constant are part of the lookup path when being used in our struct definitions.
- Dictionary
- Integer
- List
- Nullable
- String
Public Class Methods
included(base)
click to toggle source
# File lib/structured/struct.rb, line 22 def self.included(base) base.extend(ClassMethods) end
new()
click to toggle source
# File lib/structured/struct.rb, line 26 def initialize @attributes = {} end
Public Instance Methods
generate(_context)
click to toggle source
# File lib/structured/struct.rb, line 30 def generate(_context) attrs = self.class.attributes.select do |name, _| has_attribute?(name) end attrs.keys.map { |name| [name, public_send(name)] }.to_h end
has_attribute?(name)
click to toggle source
# File lib/structured/struct.rb, line 42 def has_attribute?(name) !@attributes[name].nil? end
read_attribute(name)
click to toggle source
# File lib/structured/struct.rb, line 38 def read_attribute(name) @attributes.fetch(name) { self.class.attributes[name].default_value } end
write_attribute(name, value)
click to toggle source
# File lib/structured/struct.rb, line 46 def write_attribute(name, value) @attributes[name] = value end