module Snippr::Path
Public Class Methods
list(*names)
click to toggle source
Lists all snips inside a snippr directory specified by path parts.
# File lib/snippr/path.rb, line 34 def self.list(*names) dir = path_from_name normalize_name *names Dir["#{dir}/*#{I18n.locale}.#{Snip::FILE_EXTENSION}"].map do |snip| snip.force_encoding("UTF-8").gsub(/^.*\/([^\.]+)?\.#{Snip::FILE_EXTENSION}$/, '\1').gsub(/_.*$/, '').underscore end.sort.map(&:to_sym) end
normalize_name(*names)
click to toggle source
Builds a snippr name from an array of path parts.
# File lib/snippr/path.rb, line 22 def self.normalize_name(*names) names.map do |name| Normalizer.normalize(name) end.join("/") end
path()
click to toggle source
Returns the path to the snippr files
# File lib/snippr/path.rb, line 8 def self.path if @@path.respond_to?(:call) @@path_evaled ||= @@path.call else @@path.to_s end end
path=(path)
click to toggle source
Sets the path to the snippr files.
# File lib/snippr/path.rb, line 17 def self.path=(path) @@path = path end
path_from_name(name, ext = nil)
click to toggle source
Builds a snippr path (inside the configured path) from a name and an optional extension.
# File lib/snippr/path.rb, line 29 def self.path_from_name(name, ext = nil) File.join(path, (ext ? "#{name}.#{ext}" : name)) end