Class: Fried::Schema::Attribute::DefineReader

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

Overview

Define reader based on attribute Definition

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.buildObject



6
7
8
# File 'lib/fried/schema/attribute/define_reader.rb', line 6

def self.build
  new
end

.call(attribute_definition, klass) ⇒ Object



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

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

Instance Method Details

#call(definition, klass) ⇒ Definition

Creates read method

Parameters:

Returns:



19
20
21
22
23
24
25
# File 'lib/fried/schema/attribute/define_reader.rb', line 19

def call(definition, klass)
  variable = definition.instance_variable

  klass.instance_eval do
    define_method(definition.reader) { instance_variable_get(variable) }
  end
end