Sha256: 074198e94615e6d7049912c113f3882d03559021d1f2edb2e68e76927ecdb0e1

Contents?: true

Size: 625 Bytes

Versions: 2

Compression:

Stored size: 625 Bytes

Contents

# frozen_string_literal: true

require "delegate" unless defined?(SimpleDelegator)

module Lite
  module Decorator
    class Base < SimpleDelegator

      def self.decorate(object)
        return new(object) unless object.respond_to?(:each)

        object.map { |obj| new(obj) }
      end

      def class
        if object.class.respond_to?(:table_name)
          object.class
        else
          super
        end
      end

      def object
        __getobj__
      end

      def to_model
        if object.respond_to?(:to_model)
          super
        else
          object
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lite-decorator-2.0.1 lib/lite/decorator/base.rb
lite-decorator-2.0.0 lib/lite/decorator/base.rb