lib/licensee/license_file.rb in licensee-0.0.1 vs lib/licensee/license_file.rb in licensee-0.0.2
- old
+ new
@@ -7,24 +7,33 @@
LICENSE.md
UNLICENSE
]
attr_reader :path
+ attr_accessor :contents
- def initialize(path)
+ def initialize(path=nil)
@path = File.expand_path(path)
end
def contents
@contents ||= File.open(path).read
end
alias_method :to_s, :contents
alias_method :content, :contents
def self.find(base_path)
- raise "Invalid directory" unless File.directory?(base_path)
- file = self::FILENAMES.find { |file| File.exists? File.expand_path(file, base_path) }
+ raise "Invalid directory" unless directory_exists? base_path
+ file = self::FILENAMES.find { |file| file_exists?(file, base_path) }
new(File.expand_path(file, base_path)) if file
+ end
+
+ def self.directory_exists?(base_path)
+ File.directory?(base_path)
+ end
+
+ def self.file_exists?(file, base_path)
+ File.exists? File.expand_path(file, base_path)
end
def length
@length ||= content.length
end