Class: Fried::Schema::SetDefaults
- Inherits:
-
Object
- Object
- Fried::Schema::SetDefaults
- 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
-
#set_attribute_without_checks ⇒ Object
Returns the value of attribute set_attribute_without_checks.
Class Method Summary collapse
Instance Method Summary collapse
- #call(schema, obj) ⇒ void
-
#initialize ⇒ SetDefaults
constructor
A new instance of SetDefaults.
Constructor Details
#initialize ⇒ SetDefaults
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_checks ⇒ Object
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
.build ⇒ Object
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.
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 |