lib/configurable.rb in configurable-0.4.2 vs lib/configurable.rb in configurable-0.5.0
- old
+ new
@@ -1,6 +1,6 @@
-require 'configurable/class_methods'
+require 'configurable/module_methods'
# Configurable enables the specification of configurations within a class
# definition.
#
# class ConfigClass
@@ -136,15 +136,10 @@
# long:: The long option (default: key)
# short:: The short option.
#
module Configurable
autoload(:Utils, 'configurable/utils')
-
- # Extends including classes with Configurable::ClassMethods
- def self.included(mod) # :nodoc:
- mod.extend ClassMethods if mod.kind_of?(Class)
- end
# A DelegateHash bound to self
attr_reader :config
# Initializes config, if necessary, and then calls super. If initialize
@@ -174,11 +169,11 @@
protected
# Opens the file specified by io and yield it to the block. If io is an
# IO, it will be yielded immediately, and the mode is ignored. Nil io are
- # simply ignored. The input io is always returned.
+ # simply ignored.
#
# === Usage
#
# open_io is used to compliment the io validation, to ensure that if a file
# is specified, it will be closed.
@@ -200,13 +195,17 @@
case io
when String
dir = File.dirname(io)
FileUtils.mkdir_p(dir) unless File.directory?(dir)
File.open(io, mode) {|file| yield(file) }
- when nil
+ when Integer
+ # note this does not close the io because, as far as I understand,
+ # valid integer file descriptors point to files that are already
+ # open and presumably managed elsewhere
+ yield IO.open(io, mode)
+ when nil then nil
else yield(io)
end
- io
end
# Initializes config. Default config values
# are overridden as specified by overrides.
def initialize_config(overrides={})
\ No newline at end of file