Sha256: 55899b983b70f72110fae630644a781aa66f02c422408148cadce3da9157ea3a

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

require 'shhh/app/short_name'
module Shhh
  module App
    module Output
      class Base

        attr_accessor :cli

        def initialize(cli)
          self.cli = cli
        end

        def opts
          cli.opts
        end

        @outputs = []
        class << self
          attr_accessor :outputs

          def append(output_klass)
            outputs << output_klass if outputs.is_a?(Array)
            raise "Cannot append #{output_class} after #outputs has been converted to a Hash" \
              unless outputs.is_a?(Array)
          end

          def map_outputs!
            klasses      = self.outputs
            self.outputs = Hash.new
            klasses.each { |k| self.outputs[k.required_option] = k }
            outputs
          end

          def options_to_outputs
            map_outputs! if outputs.is_a?(Array)
            outputs
          end
        end

        def self.inherited(klass)
          klass.instance_eval do
            class << self
              attr_writer :required_option
            end

            klass.required_option = nil

            class << self
              def required_option(_option = nil)
                self.required_option = _option if _option
                @required_option
              end
            end
          end
          klass.extend(Shhh::App::ShortName)
          Shhh::App::Output::Base.append klass
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shhh-1.7.0 lib/shhh/app/output/base.rb
shhh-1.6.5 lib/shhh/app/output/base.rb
shhh-1.6.4 lib/shhh/app/output/base.rb
shhh-1.6.3 lib/shhh/app/output/base.rb
shhh-1.6.2 lib/shhh/app/output/base.rb
shhh-1.6.1 lib/shhh/app/output/base.rb
shhh-1.5.4 lib/shhh/app/output/base.rb