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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/vimpack/models/script.rb', line 66
def self.get(name)
_type = name.include?('/') ? :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.login, :author_email => '',
:repo_owner => repo.owner.login
}
when :vimscript
script_hash = get_vimscript(name)
raise ScriptNotFound.new(name) if script_hash.nil?
end
Script.new(script_hash)
end
|
.info(name) ⇒ Object
86
87
88
|
# File 'lib/vimpack/models/script.rb', line 86
def self.info(name)
get(name)
end
|
.search(q, types = [], limit = 10, offset = 0) ⇒ Object
60
61
62
63
64
|
# File 'lib/vimpack/models/script.rb', line 60
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
130
131
132
|
# File 'lib/vimpack/models/script.rb', line 130
def bundle_path
Repo.bundle_path.join(name)
end
|
#commits ⇒ Object
44
45
46
47
48
|
# File 'lib/vimpack/models/script.rb', line 44
def commits
@commits ||= self.class.commits(github_short_url).sort do |a, b|
a.authored_date <=> b.authored_date
end
end
|
#github_short_url ⇒ Object
33
34
35
|
# File 'lib/vimpack/models/script.rb', line 33
def github_short_url
@github_short_url ||= "#{repo_owner}/#{name}"
end
|
#install!(link_to_bundle = true) ⇒ Object
#install_path ⇒ Object
121
122
123
124
125
126
127
128
|
# File 'lib/vimpack/models/script.rb', line 121
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
117
118
119
|
# File 'lib/vimpack/models/script.rb', line 117
def installable?
Repo.initialized? && !installed?
end
|
#set_attributes_from_github ⇒ Object
37
38
39
40
41
42
|
# File 'lib/vimpack/models/script.rb', line 37
def set_attributes_from_github
@repo = self.class.repo(github_short_url)
instance_variable_set("@description".to_sym, @repo[:description])
instance_variable_set("@url".to_sym, @repo[:clone_url])
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
50
51
52
53
54
55
56
57
58
|
# File 'lib/vimpack/models/script.rb', line 50
def set_version_from_github
last_commit = commits.first
if type == 'github'
@version = last_commit.sha
else
@version = last_commit.commit.message.split(':')[0][0..10].gsub(/Version /, '')
end
@version_date = last_commit.commit.author.date
end
|