Sha256: a5abc55836b39115caa233ea96035cb6002d19233d05f031b3d3952bd221e976

Contents?: true

Size: 804 Bytes

Versions: 32

Compression:

Stored size: 804 Bytes

Contents

module Symphonia
  # This class decorate general entity
  class EntityDecorator < SimpleDelegator

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

    def registered_attributes
      __getobj__.class.registered_attributes
    end

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

    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

    # def name
    #   @name ||= super || registered_attributes.find { |name, a| name == :name }.last
    # end
    #
    # def title
    #   super || name || to_s
    # end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
symphonia-6.0.5 lib/symphonia/entity_decorator.rb
symphonia-6.0.4 lib/symphonia/entity_decorator.rb
symphonia-6.0.2 lib/symphonia/entity_decorator.rb
symphonia-6.0.1 lib/symphonia/entity_decorator.rb
symphonia-6.0.0 lib/symphonia/entity_decorator.rb
symphonia-5.0.6 lib/symphonia/entity_decorator.rb
symphonia-5.0.5 lib/symphonia/entity_decorator.rb
symphonia-5.0.4 lib/symphonia/entity_decorator.rb
symphonia-5.0.3 lib/symphonia/entity_decorator.rb
symphonia-5.0.0 lib/symphonia/entity_decorator.rb
symphonia-4.2.0 lib/symphonia/entity_decorator.rb
symphonia-4.1.3 lib/symphonia/entity_decorator.rb
symphonia-4.1.2 lib/symphonia/entity_decorator.rb
symphonia-4.1.1 lib/symphonia/entity_decorator.rb
symphonia-4.1.0 lib/symphonia/entity_decorator.rb
symphonia-4.0.1 lib/symphonia/entity_decorator.rb
symphonia-4.0.0 lib/symphonia/entity_decorator.rb
symphonia-3.4.0 lib/symphonia/entity_decorator.rb
symphonia-3.3.4 lib/symphonia/entity_decorator.rb
symphonia-3.3.3 lib/symphonia/entity_decorator.rb