Module: Appjam::View

Extended by:
View
Included in:
View
Defined in:
lib/appjam/view.rb

Instance Method Summary collapse

Instance Method Details

#class_config(klass) ⇒ Object

:stopdoc:



25
26
27
28
29
30
31
# File 'lib/appjam/view.rb', line 25

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

#enableObject

Enables hirb and reads a config file from the main repo’s config/hirb.yml.



6
7
8
9
10
11
12
# File 'lib/appjam/view.rb', line 6

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

#render(object, options = {}, return_obj = false) ⇒ Object

Renders any object via Hirb. Options are passed directly to Hirb::Console.render_output.



16
17
18
19
20
21
22
# File 'lib/appjam/view.rb', line 16

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

#render_object(object, options = {}, return_obj = false) ⇒ Object



41
42
43
44
45
# File 'lib/appjam/view.rb', line 41

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

#silent_object?(obj) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/appjam/view.rb', line 37

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

#toggle_pagerObject



33
34
35
# File 'lib/appjam/view.rb', line 33

def toggle_pager
  Hirb::View.toggle_pager
end