Class: Vimpack::Models::Script
Defined Under Namespace
Classes: AlreadyInstalled, NotInstalled, ScriptNotFound
Constant Summary
collapse
- SCRIPT_TYPES =
[ 'utility', 'color scheme', 'syntax', 'ftplugin',
'indent', 'game', 'plugin', 'patch', 'github' ]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
included
Constructor Details
#initialize(attrs = {}) ⇒ Script
Returns a new instance of Script.
22
23
24
25
|
# File 'lib/vimpack/models/script.rb', line 22
def initialize(attrs={})
set_attributes_from_input(attrs)
set_attributes_from_github
end
|
Instance Attribute Details
#author ⇒ Object
13
14
15
|
# File 'lib/vimpack/models/script.rb', line 13
def author
@author
end
|
#author_email ⇒ Object
13
14
15
|
# File 'lib/vimpack/models/script.rb', line 13
def author_email
@author_email
end
|
#description ⇒ Object
15
16
17
|
# File 'lib/vimpack/models/script.rb', line 15
def description
@description
end
|
#name ⇒ Object
13
14
15
|
# File 'lib/vimpack/models/script.rb', line 13
def name
@name
end
|
#repo_owner ⇒ Object
17
18
19
|
# File 'lib/vimpack/models/script.rb', line 17
def repo_owner
@repo_owner
end
|
#type ⇒ Object
13
14
15
|
# File 'lib/vimpack/models/script.rb', line 13
def type
@type
end
|
#url ⇒ Object
15
16
17
|
# File 'lib/vimpack/models/script.rb', line 15
def url
@url
end
|
#version ⇒ Object
13
14
15
|
# File 'lib/vimpack/models/script.rb', line 13
def version
@version
end
|
#version_date ⇒ Object
13
14
15
|
# File 'lib/vimpack/models/script.rb', line 13
def version_date
@version_date
end
|
Class Method Details
.get(name) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/vimpack/models/script.rb', line 62
def self.get(name)
_type = (name =~ /\//) ? :github : :vimscript
case _type
when :github
repo_key = name.split("/")[-2..-1].join("/").split(".").first repo = repository(repo_key)
script_hash =
{ :name => repo.name, :type => 'github',
:description => repo.description, :script_version => '',
:author => repo.owner, :author_email => '',
:repo_owner => repo.owner
}
when :vimscript
script_hash = get_vimscript(name)
raise ScriptNotFound.new(name) if script_hash.nil?
end
Script.new(script_hash)
end
|
.info(name) ⇒ Object
82
83
84
|
# File 'lib/vimpack/models/script.rb', line 82
def self.info(name)
get(name)
end
|
.search(q, types = [], limit = 10, offset = 0) ⇒ Object
56
57
58
59
60
|
# File 'lib/vimpack/models/script.rb', line 56
def self.search(q, types = [], limit = 10, offset = 0)
search_vimscripts(q, types).map do |vimscript|
Script.new(vimscript)
end
end
|
Instance Method Details
#bundle_path ⇒ Object
126
127
128
|
# File 'lib/vimpack/models/script.rb', line 126
def bundle_path
Repo.bundle_path.join(name)
end
|
#commits ⇒ Object
40
41
42
43
44
|
# File 'lib/vimpack/models/script.rb', line 40
def commits
@commits ||= self.class.commits(@repo).sort do |a, b|
a.authored_date <=> b.authored_date
end
end
|
#install!(link_to_bundle = true) ⇒ Object
#install_path ⇒ Object
117
118
119
120
121
122
123
124
|
# File 'lib/vimpack/models/script.rb', line 117
def install_path
case type
when 'github'
Repo.script_path.join(type.gsub(' ', '_'), repo_owner, name)
else
Repo.script_path.join(type.gsub(' ', '_'), name)
end
end
|
#installable? ⇒ Boolean
113
114
115
|
# File 'lib/vimpack/models/script.rb', line 113
def installable?
Repo.initialized? && !installed?
end
|
#set_attributes_from_github ⇒ Object
33
34
35
36
37
38
|
# File 'lib/vimpack/models/script.rb', line 33
def set_attributes_from_github
url = "#{repo_owner}/#{name}"
@repo = self.class.repo(url)
[ :url, :description ].each { |attr| instance_variable_set("@#{attr}".to_sym, @repo[attr]) }
set_version_from_github
end
|
27
28
29
30
31
|
# File 'lib/vimpack/models/script.rb', line 27
def set_attributes_from_input(attrs)
attrs.each_pair do |attr, value|
instance_variable_set("@#{attr}".to_sym, value)
end
end
|
#set_version_from_github ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/vimpack/models/script.rb', line 46
def set_version_from_github
last_commit = commits.last
if type == 'github'
@version = last_commit.id
else
@version = last_commit.message[0..10].gsub(/Version /, '')
end
@version_date = last_commit.authored_date
end
|