Class: OrgMode::Configuration
- Inherits:
-
Object
- Object
- OrgMode::Configuration
- Defined in:
- lib/org_mode/configuration.rb
Defined Under Namespace
Classes: Error, IOError, NonExistant, ScriptError
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
readonly
Instance.
-
#file_name ⇒ Object
readonly
Instance.
-
#path ⇒ Object
readonly
Instance.
Class Method Summary collapse
- .backup_dir ⇒ Object
-
.create_default_config(base_dir = nil, file_name = nil) ⇒ Object
Creates a minimal example configuration.
- .load(base_dir = nil, file_name = nil) ⇒ Object
-
.method_missing(f, *a) ⇒ Object
forward all to our singleton.
- .path ⇒ Object
Instance Method Summary collapse
-
#initialize(a_base_dir = nil, a_file_name = nil) ⇒ Configuration
constructor
Initializes loader and generates file-path.
-
#read_and_evaluate ⇒ Object
Reads a config file and avaluates it.
Constructor Details
#initialize(a_base_dir = nil, a_file_name = nil) ⇒ Configuration
Initializes loader and generates file-path
106 107 108 109 110 |
# File 'lib/org_mode/configuration.rb', line 106 def initialize(a_base_dir=nil, a_file_name=nil) @base_dir = Pathname.new(a_base_dir || ENV['HOME']) @file_name = Pathname.new(a_file_name || '.orgmoderc') @path = @base_dir + @file_name end |
Instance Attribute Details
#base_dir ⇒ Object (readonly)
Instance
103 104 105 |
# File 'lib/org_mode/configuration.rb', line 103 def base_dir @base_dir end |
#file_name ⇒ Object (readonly)
Instance
103 104 105 |
# File 'lib/org_mode/configuration.rb', line 103 def file_name @file_name end |
#path ⇒ Object (readonly)
Instance
103 104 105 |
# File 'lib/org_mode/configuration.rb', line 103 def path @path end |
Class Method Details
.backup_dir ⇒ Object
88 89 90 |
# File 'lib/org_mode/configuration.rb', line 88 def backup_dir @singleton.base_dir + '.orgmode/backups' end |
.create_default_config(base_dir = nil, file_name = nil) ⇒ Object
Creates a minimal example configuration
Returns the default config
137 138 139 140 141 |
# File 'lib/org_mode/configuration.rb', line 137 def self.create_default_config(base_dir=nil,file_name=nil) new_config = Configuration.new(base_dir,file_name) DefaultConfiguration.write_to( new_config.path ) return new_config.read_and_evaluate end |
.load(base_dir = nil, file_name = nil) ⇒ Object
79 80 81 82 |
# File 'lib/org_mode/configuration.rb', line 79 def load(base_dir=nil, file_name=nil) @singleton = new(base_dir,file_name) @config = @singleton.read_and_evaluate end |
.method_missing(f, *a) ⇒ Object
forward all to our singleton
93 94 95 96 97 98 |
# File 'lib/org_mode/configuration.rb', line 93 def method_missing(f,*a) if @config.respond_to?(f) return @config.send(f, *a) end super end |
.path ⇒ Object
84 85 86 |
# File 'lib/org_mode/configuration.rb', line 84 def path @singleton.path end |
Instance Method Details
#read_and_evaluate ⇒ Object
Reads a config file and avaluates it.
Returns a Configuration object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/org_mode/configuration.rb', line 116 def read_and_evaluate contents = ::File.open(path).read instance_eval <<-RUBY, path, 0 ::Configuration.for('org-mode') do #{contents} end RUBY ::Configuration.for('org-mode') rescue ::Errno::ENOENT => e raise NonExistant, "config file does not exist" rescue ::IOError, ::SystemCallError => e raise IOError, "problem loading config: #{e}" rescue ::ScriptError => e raise ScriptError, "problem loading config: #{e}" end |