Class: Fried::Schema::SetDefaults

Inherits:
Object
  • Object
show all
Defined in:
lib/fried/schema/set_defaults.rb

Overview

Set defaults values for all attributes in schema definitions while ignoring type checking

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSetDefaults

Returns a new instance of SetDefaults.



10
11
12
# File 'lib/fried/schema/set_defaults.rb', line 10

def initialize
  self.set_attribute_without_checks = SetAttributeWithoutChecks.new
end

Instance Attribute Details

#set_attribute_without_checksObject

Returns the value of attribute set_attribute_without_checks.



8
9
10
# File 'lib/fried/schema/set_defaults.rb', line 8

def set_attribute_without_checks
  @set_attribute_without_checks
end

Class Method Details

.buildObject



14
15
16
17
18
# File 'lib/fried/schema/set_defaults.rb', line 14

def self.build
  new.tap do |instance|
    instance.set_attribute_without_checks = SetAttributeWithoutChecks.build
  end
end

.call(schema, obj) ⇒ Object



20
21
22
23
# File 'lib/fried/schema/set_defaults.rb', line 20

def self.call(schema, obj)
  instance = build
  instance.(schema, obj)
end

Instance Method Details

#call(schema, obj) ⇒ void

This method returns an undefined value.

Parameters:



28
29
30
31
32
33
# File 'lib/fried/schema/set_defaults.rb', line 28

def call(schema, obj)
  schema.each_attribute do |attribute|
    value = attribute.extract_default
    set_attribute_without_checks.(obj, attribute, value)
  end
end