Sha256: f48dcde34338b9161aef00cc242e0afc2894148da9a2c5542dd0288cb00db15b

Contents?: true

Size: 1.31 KB

Versions: 26

Compression:

Stored size: 1.31 KB

Contents

module Appjam
  module View
    extend self

    # Enables hirb and reads a config file from the main repo's config/hirb.yml.
    def enable
      unless @enabled
        Hirb::View.enable(:config_file=>File.join(Appjam.repo.config_dir, 'hirb.yml'))
        Hirb::Helpers::Table.filter_any = true
      end
      @enabled = true
    end

    # Renders any object via Hirb. Options are passed directly to
    # {Hirb::Console.render_output}[http://tagaholic.me/hirb/doc/classes/Hirb/Console.html#M000011].
    def render(object, options={}, return_obj=false)
      if options[:inspect]
        puts(object.inspect)
      else
        render_object(object, options, return_obj) unless silent_object?(object)
      end
    end

    #:stopdoc:
    def class_config(klass)
      opts = (Hirb::View.formatter_config[klass] || {}).dup
      opts.delete(:ancestor)
      opts.merge!((opts.delete(:options) || {}).dup)
      OptionParser.make_mergeable!(opts)
      opts
    end

    def toggle_pager
      Hirb::View.toggle_pager
    end

    def silent_object?(obj)
      [nil,false,true].include?(obj)
    end

    def render_object(object, options={}, return_obj=false)
      options[:class] ||= :auto_table
      render_result = Hirb::Console.render_output(object, options)
      return_obj ? object : render_result
    end
    #:startdoc:
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
appjam-0.1.8.11 lib/appjam/view.rb
appjam-0.1.8.10 lib/appjam/view.rb
appjam-0.1.8.9 lib/appjam/view.rb
appjam-0.1.8.8 lib/appjam/view.rb
appjam-0.1.8.7 lib/appjam/view.rb
appjam-0.1.8.6 lib/appjam/view.rb
appjam-0.1.8.5 lib/appjam/view.rb
appjam-0.1.8.4 lib/appjam/view.rb
appjam-0.1.8.3 lib/appjam/view.rb
appjam-0.1.8.2 lib/appjam/view.rb
appjam-0.1.8.1 lib/appjam/view.rb
appjam-0.1.8 lib/appjam/view.rb
appjam-0.1.8.pre13 lib/appjam/view.rb
appjam-0.1.8.pre12 lib/appjam/view.rb
appjam-0.1.8.pre11 lib/appjam/view.rb
appjam-0.1.8.pre10 lib/appjam/view.rb
appjam-0.1.8.pre9 lib/appjam/view.rb
appjam-0.1.8.pre7 lib/appjam/view.rb
appjam-0.1.8.pre6 lib/appjam/view.rb
appjam-0.1.8.pre5 lib/appjam/view.rb