Method: BBLib::Attrs#attr_dir

Defined in:
lib/bblib/core/mixins/attrs.rb

#attr_dir(*methods, **opts) ⇒ Object



340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/bblib/core/mixins/attrs.rb', line 340

def attr_dir(*methods, **opts)
  methods.each do |method|
    attr_custom(method, opts) do |arg|
      exists = Dir.exist?(arg.to_s)
      if !exists && (opts[:mkdir] || opts[:mkpath]) && arg
        FileUtils.mkpath(arg.to_s)
        exists = Dir.exist?(arg.to_s)
      end
      raise ArgumentError, "#{method} must be set to a valid directory. '#{arg}' cannot be found." unless exists || (opts[:allow_nil] && arg.nil?)
      arg
    end
  end
end