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

- (AutoConfig) initialize(attrs = {})



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

- (Object) host_os

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

- (Object) color

--------------------------------------- Defaults



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

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

- (Object) frontend



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

- (Boolean) has_less?

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



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

- (Object) pager



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

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

- (Object) shell_escape



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

- (Boolean) unix?



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

- (Boolean) windows?



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