Class: Fried::Schema::Attribute::DefineMethods

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

Overview

Define methods based on attributes registered in Definition

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefineMethods

Returns a new instance of DefineMethods.



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

def initialize
  self.define_reader = ::Fried::Schema::Attribute::DefineReader.new
  self.define_writer = ::Fried::Schema::Attribute::DefineWriter.new
end

Instance Attribute Details

#define_readerObject

Returns the value of attribute define_reader.



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

def define_reader
  @define_reader
end

#define_writerObject

Returns the value of attribute define_writer.



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

def define_writer
  @define_writer
end

Class Method Details

.buildObject



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

def self.build
  new.tap do |instance|
    instance.define_reader = ::Fried::Schema::Attribute::DefineReader.build
    instance.define_writer = ::Fried::Schema::Attribute::DefineWriter.build
  end
end

.call(attribute_definition, klass) ⇒ Object



24
25
26
27
# File 'lib/fried/schema/attribute/define_methods.rb', line 24

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

Instance Method Details

#call(attribute_definition, klass) ⇒ AttributeDefinition

Creates methods to read/write attribute with type checking

Parameters:

  • attribute_definition (AttributeDefinition)
  • klass (Class, Module)

Returns:

  • (AttributeDefinition)


33
34
35
36
37
# File 'lib/fried/schema/attribute/define_methods.rb', line 33

def call(attribute_definition, klass)
  define_reader.(attribute_definition, klass)
  define_writer.(attribute_definition, klass)
  attribute_definition
end