Sha256: 3bd67400e7a187bed38d73d5b26d374f2f9fc41bb74baab29cdd6a1e81d9e6d6

Contents?: true

Size: 627 Bytes

Versions: 6

Compression:

Stored size: 627 Bytes

Contents

# frozen_string_literal: true

require 'delegate'

module Lite
  module Decorator
    class Base < SimpleDelegator

      class << self

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

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

      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

6 entries across 6 versions & 1 rubygems

Version Path
lite-decorator-1.1.1 lib/lite/decorator/base.rb
lite-decorator-1.1.0 lib/lite/decorator/base.rb
lite-decorator-1.0.3 lib/lite/decorator/base.rb
lite-decorator-1.0.2 lib/lite/decorator/base.rb
lite-decorator-1.0.1 lib/lite/decorator/base.rb
lite-decorator-1.0.0 lib/lite/decorator/base.rb