Sha256: 18f49b011f5560fb21410dee647d4be430c36a4a76e2bec40088377530cf0b4e

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

module Candle
  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(Candle.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

6 entries across 6 versions & 1 rubygems

Version Path
candle-0.0.7 lib/candle/view.rb
candle-0.0.6 lib/candle/view.rb
candle-0.0.4 lib/candle/view.rb
candle-0.0.3 lib/candle/view.rb
candle-0.0.2 lib/candle/view.rb
candle-0.0.1 lib/candle/view.rb