Sha256: 2d06e9a2a4797b3949e1a47cdf2b3b35efe5ccaa27dfd0fe4af6467595f039d2

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

module Rails
  module AddOns
    module Service
        module Messages
          private

          def initialize_messages
            @messages = []
          end

          def say(what, &block)
            @indent ||= 0
            if block_given?
              @indent += 1
              output "#{output_prefix}#{("  " * @indent)}#{what}..."
              block_result = yield
              say_done
              @indent -= 1
              block_result
            else
              output "#{output_prefix}#{("  " * @indent)}#{what}"
            end
          end

          def say_done
            say "  => Done"
          end

          def output_prefix
            "[#{self.class.name}] "
          end

          def output(what)
            @messages << what
            puts what unless silenced?
          end

          def silenced?
            !!@options[:silence]
          end

          def copy_messages_to_result
            @result.instance_variable_set(:@messages, @messages)
          end
        end
      end
    end
  end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails-add_ons-1.2.0 app/services/rails/add_ons/service/messages.rb
rails-add_ons-1.1.0 app/services/rails/add_ons/service/messages.rb
rails-add_ons-1.0.0 app/services/rails/add_ons/service/messages.rb