Class: Yap::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/yap/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/yap/configuration.rb', line 42

def initialize
  @yap_addons_configuration_path = yap_path.join('addons.yml')

  @addon_paths = [
    # "#{File.dirname(__FILE__)}/../../addons",
    # "#{ENV['HOME']}/.yap/addons"
  ].concat(Gem.path.map { |gems_path| "#{gems_path}/gems" }).map do |path|
    File.expand_path(path)
  end

  @rcfiles = [
    "#{ENV['HOME']}/.yaprc",
    preferred_yaprc_path
  ]
end

Instance Attribute Details

#addon_pathsObject

Returns the value of attribute addon_paths.



11
12
13
# File 'lib/yap/configuration.rb', line 11

def addon_paths
  @addon_paths
end

#rcfilesObject

Returns the value of attribute rcfiles.



12
13
14
# File 'lib/yap/configuration.rb', line 12

def rcfiles
  @rcfiles
end

#yap_addons_configuration_pathObject

Returns the value of attribute yap_addons_configuration_path.



13
14
15
# File 'lib/yap/configuration.rb', line 13

def yap_addons_configuration_path
  @yap_addons_configuration_path
end

#yap_binpathObject

Returns the value of attribute yap_binpath.



14
15
16
# File 'lib/yap/configuration.rb', line 14

def yap_binpath
  @yap_binpath
end

Class Method Details

.option(name, type = nil, default: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yap/configuration.rb', line 16

def self.option(name, type=nil, default: nil)
  reader_method = name.to_s
  define_method(reader_method) do
    return default unless instance_variable_defined?("@#{name}")
    value = instance_variable_get("@#{name}")
    return !!value if type == :boolean
    value
  end

  writer_method = "#{reader_method}="
  define_method(writer_method) do |value|
    instance_variable_set("@#{name}", value)
  end

  if type == :boolean
    query_method = "#{reader_method}?"
    alias_method query_method, reader_method
  end
end

Instance Method Details

#path_for(part) ⇒ Object



58
59
60
# File 'lib/yap/configuration.rb', line 58

def path_for(part)
  yap_path.join(part)
end

#preferred_yaprc_pathObject



62
63
64
# File 'lib/yap/configuration.rb', line 62

def preferred_yaprc_path
  yap_path.join("yaprc")
end

#yap_pathObject



70
71
72
# File 'lib/yap/configuration.rb', line 70

def yap_path
  Pathname.new "#{ENV['HOME']}/.yap"
end

#yaprc_template_pathObject



66
67
68
# File 'lib/yap/configuration.rb', line 66

def yaprc_template_path
  Pathname.new(File.dirname(__FILE__)).join('../../rcfiles/yaprc')
end