Class: AbcJsonapi::VirtualAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/abc_jsonapi/virtual_attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, name:, block:) ⇒ VirtualAttribute

Returns a new instance of VirtualAttribute.



5
6
7
8
9
# File 'lib/abc_jsonapi/virtual_attribute.rb', line 5

def initialize(model:, name:, block:)
  @model = model
  @name = name
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/abc_jsonapi/virtual_attribute.rb', line 3

def block
  @block
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'lib/abc_jsonapi/virtual_attribute.rb', line 3

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/abc_jsonapi/virtual_attribute.rb', line 3

def name
  @name
end

Instance Method Details

#serializable_hashObject



11
12
13
# File 'lib/abc_jsonapi/virtual_attribute.rb', line 11

def serializable_hash
  { name.to_sym => block.call(model) }
end