Class: ORI::AutoConfig

Inherits:
Object show all
Defined in:
lib/ori/auto_config.rb

Overview

Propose config defaults based on OS and environment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ AutoConfig

Returns a new instance of AutoConfig.



11
12
13
14
# File 'lib/ori/auto_config.rb', line 11

def initialize(attrs = {})
  attrs.each {|k, v| send("#{k}=", v)}
  clear_cache
end

Instance Attribute Details

#host_osObject

Value of RbConfig::Config["host_os"].

linux-gnu
mswin32
cygwin


9
10
11
# File 'lib/ori/auto_config.rb', line 9

def host_os
  @host_os
end

Instance Method Details

#colorObject

————————————— Defaults



46
47
48
# File 'lib/ori/auto_config.rb', line 46

def color
  @cache[:color] ||= unix?? true : false
end

#frontendObject



50
51
52
# File 'lib/ori/auto_config.rb', line 50

def frontend
  @cache[:frontend] ||= unix?? "ri -T -f ansi %s" : "ri -T %s"
end

#has_less?Boolean

————————————— Accessors and pseudo-accessors

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/ori/auto_config.rb', line 18

def has_less?
  @cache[:has_less] ||= begin
    require_host_os
    !!@host_os.match(/cygwin|darwin|freebsd|gnu|linux/i)
  end
end

#pagerObject



54
55
56
# File 'lib/ori/auto_config.rb', line 54

def pager
  @cache[:pager] ||= has_less?? "less -R" : "more"
end

#shell_escapeObject



58
59
60
61
62
63
64
65
66
# File 'lib/ori/auto_config.rb', line 58

def shell_escape
  @cache[:shell_escape] ||= if unix?
    :unix
  elsif windows?
    :windows
  else
    nil
  end
end

#unix?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/ori/auto_config.rb', line 30

def unix?
  @cache[:is_unix] ||= begin
    require_host_os
    !!@host_os.match(/cygwin|darwin|freebsd|gnu|linux|sunos|solaris/i)
  end
end

#windows?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
# File 'lib/ori/auto_config.rb', line 37

def windows?
  @cache[:is_windows] ||= begin
    require_host_os
    !!@host_os.match(/mswin|windows/i)
  end
end