Sha256: e1bec38ac7465642c2fda6cb59f1622ba5111141c36b859a086e68a7ffcfb12c

Contents?: true

Size: 1.11 KB

Versions: 23

Compression:

Stored size: 1.11 KB

Contents

require 'sugar-high/blank'
require 'sugar-high/arguments'
require 'sugar-high/path'
require 'sugar-high/regexp'
require 'sugar-high/string'
require 'sugar-high/file_mutate'
require 'sugar-high/file_ext'

class File   
  include SugarHigh::FileExt
  extend  SugarHigh::FileExt::ClassMethods    
end

class Symbol
  def as_filename
    self.to_s.underscore
  end
  
  def valid_file_command?
    [:read, :remove, :delete].include? self
  end
  
  def file
    as_filename.file
  end  
end                 

class NilClass
  def valid_file_command?
    false
  end
end  

class Array
  def file_names ext = '*'
    self.map{|a| a.gsub( /(.*)\//, '').gsub(/\.#{Regexp.escape(ext.to_s)}/, '')}
  end
end

class String
  def as_filename
    self.underscore  
  end

  def valid_file_command?
    self.to_sym.valid_file_command?
  end

  def file
    return ::File.new(self) if ::File.file?(self)
    raise "No file found at #{self}"
  end

  def dir
    return ::Dir.new(self) if ::File.directory?(self)
    raise "No file found at #{self}"
  end

  def new_file
    begin 
      file
    rescue
      File.open(self, 'w')    
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
sugar-high-0.5.5 lib/sugar-high/file.rb
sugar-high-0.5.4 lib/sugar-high/file.rb
sugar-high-0.5.3 lib/sugar-high/file.rb
sugar-high-0.5.1 lib/sugar-high/file.rb
sugar-high-0.5.0 lib/sugar-high/file.rb
sugar-high-0.4.9.5 lib/sugar-high/file.rb
sugar-high-0.4.9.3 lib/sugar-high/file.rb
sugar-high-0.4.9.2 lib/sugar-high/file.rb
sugar-high-0.4.9.1 lib/sugar-high/file.rb
sugar-high-0.4.9 lib/sugar-high/file.rb
sugar-high-0.4.8 lib/sugar-high/file.rb
sugar-high-0.4.7 lib/sugar-high/file.rb
sugar-high-0.4.6.4 lib/sugar-high/file.rb
sugar-high-0.4.6.3 lib/sugar-high/file.rb
sugar-high-0.4.6.2 lib/sugar-high/file.rb
sugar-high-0.4.6.1 lib/sugar-high/file.rb
sugar-high-0.4.6 lib/sugar-high/file.rb
sugar-high-0.4.5.2 lib/sugar-high/file.rb
sugar-high-0.4.5 lib/sugar-high/file.rb
sugar-high-0.4.4.2 lib/sugar-high/file.rb