class SocialSnippet::Repository::Models::Package
Public Class Methods
core()
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 101 def self.core @@core end
core=(new_core)
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 105 def self.core=(new_core) @@core = new_core end
Public Instance Methods
add_dependency(new_name, new_ref)
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 45 def add_dependency(new_name, new_ref) add_to_set :dependencies_array => { :name => new_name, :ref => new_ref, } @dependencies_cache = nil end
add_directory(path)
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 25 def add_directory(path) path = normalize_path(path) add_path path add_path path + "/" dir_path = real_path(path) core.storage.mkdir_p dir_path end
add_file(path, data)
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 33 def add_file(path, data) path = normalize_path(path) add_path path file_path = real_path(path) core.storage.mkdir_p ::File.dirname(file_path) core.storage.write file_path, data end
add_path(path)
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 21 def add_path(path) push :paths => path end
core()
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 97 def core @@core end
dependencies()
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 53 def dependencies @dependencies_cache ||= dependencies_array.inject(::Hash.new) do |dependencies, info| dependencies[info[:name]] = info[:ref] dependencies end end
directory?(path)
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 41 def directory?(path) core.storage.directory? real_path(normalize_path path) end
display_name()
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 13 def display_name name || "#{repo_name}@#{rev_hash}" end
glob(glob_pattern)
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 77 def glob(glob_pattern) paths.select do |path| next if /\/$/ === path ::File.fnmatch glob_pattern, path, ::File::FNM_PATHNAME end end
has_dependencies?()
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 60 def has_dependencies? not dependencies.empty? end
normalize_path(path)
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 17 def normalize_path(path) ::Pathname.new(path).cleanpath.to_s end
parse_snippet_json()
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 73 def parse_snippet_json ::JSON.parse(snippet_json_text) end
real_path(path = nil)
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 84 def real_path(path = nil) core.config.package_path repo_name, rev_hash, path end
snippet_json()
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 69 def snippet_json @snippet_json ||= parse_snippet_json end
snippet_json_text()
click to toggle source
# File lib/social_snippet/repository/models/package.rb, line 64 def snippet_json_text json_path = real_path("snippet.json") core.storage.read json_path end
snippet_path(path = nil)
click to toggle source
path from snippet_json
# File lib/social_snippet/repository/models/package.rb, line 89 def snippet_path(path = nil) if snippet_json["main"].nil? real_path path else real_path ::File.join(snippet_json["main"], path) end end