Class: Symphonia::EntityDecorator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/symphonia/entity_decorator.rb

Overview

This class decorate general entity

Instance Method Summary collapse

Constructor Details

#initialize(entity, view_context) ⇒ EntityDecorator

Returns a new instance of EntityDecorator.



5
6
7
8
# File 'lib/symphonia/entity_decorator.rb', line 5

def initialize(entity, view_context)
  @view_context = view_context
  super(entity)
end

Instance Method Details

#attributes(&block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/symphonia/entity_decorator.rb', line 18

def attributes(&block)
  registered_attributes.collect do |name, attr|
    value = __getobj__.format_value(name, @view_context)
    yield name, value, attr if block_given?
    [name, value]
  end.to_h
end

#label(name, **options) ⇒ Object



14
15
16
# File 'lib/symphonia/entity_decorator.rb', line 14

def label(name, **options)
  __getobj__.class.human_attribute_name name, options
end

#registered_attributesObject



10
11
12
# File 'lib/symphonia/entity_decorator.rb', line 10

def registered_attributes
  __getobj__.class.registered_attributes
end