Sha256: 2b7d2b54cb553f4869ad997e97fef17a6f083bc367f7a0f57c38861597f9ca99

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

module Lookbook
  # @api private
  module InspectableEntity
    extend ActiveSupport::Concern

    included do
      def source
        source_code = if custom_source?
          File.read(source_file_path)
        else
          src = CodeIndenter.call(code_object.source)
          begin
            send(:format_source, src)
          rescue NoMethodError
            src
          end
        end

        source_code.strip_heredoc.strip
      end

      def source_lang
        custom_source? ? Lang.guess(source_file_path, :ruby) : Lang.find(:ruby)
      end

      def custom_source?
        source_file_path.present?
      end

      protected

      attr_reader :code_object

      def source_file_path
        @_source_path ||= if code_object.has_tag?(:source)
          source_path = code_object.tag(:source).value
          unless source_path.present? && File.exist?(source_path)
            raise LookbookError, "Could not find source file '#{source_path}'"
          end
          source_path
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lookbook-2.0.0.beta.3 lib/lookbook/entities/concerns/inspectable_entity.rb
lookbook-2.0.0.beta.2 lib/lookbook/entities/concerns/inspectable_entity.rb
lookbook-2.0.0.beta.1 lib/lookbook/entities/concerns/inspectable_entity.rb
lookbook-2.0.0.beta.0 lib/lookbook/entities/concerns/inspectable_entity.rb