Class: Fried::Schema::Attribute::DefineWriter

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

Overview

Define writer based on attribute Definition with type-checking

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefineWriter

Returns a new instance of DefineWriter.



9
10
11
# File 'lib/fried/schema/attribute/define_writer.rb', line 9

def initialize
  self.is = ::Fried::Typings::Is
end

Instance Attribute Details

#isObject

Returns the value of attribute is.



7
8
9
# File 'lib/fried/schema/attribute/define_writer.rb', line 7

def is
  @is
end

Class Method Details

.buildObject



13
14
15
# File 'lib/fried/schema/attribute/define_writer.rb', line 13

def self.build
  new
end

.call(attribute_definition, klass) ⇒ Object



17
18
19
20
# File 'lib/fried/schema/attribute/define_writer.rb', line 17

def self.call(attribute_definition, klass)
  instance = build
  instance.(attribute_definition, klass)
end

Instance Method Details

#call(definition, klass) ⇒ Definition

Creates write method with type-checking

Parameters:

Returns:



26
27
28
29
# File 'lib/fried/schema/attribute/define_writer.rb', line 26

def call(definition, klass)
  is_a = is[definition.type]
  define_writer(definition, is_a, klass)
end