Class: Githubris::Gist
Instance Method Summary
collapse
Methods included from Publicity
#privatize!, #public?, #publicize!
Methods inherited from Base
#==, #initialize, #swap_attributes
Instance Method Details
#delete! ⇒ Object
29
30
31
|
# File 'lib/githubris/gist.rb', line 29
def delete!
@api.delete_gist(@attributes[:id])
end
|
#history ⇒ Object
33
34
35
36
37
|
# File 'lib/githubris/gist.rb', line 33
def history
@attributes[:history].map do |gist_data|
Githubris::Gist.new(gist_data)
end
end
|
#new? ⇒ Boolean
67
68
69
70
71
72
73
|
# File 'lib/githubris/gist.rb', line 67
def new?
reload
rescue Githubris::Error
true
else
false
end
|
#reload ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/githubris/gist.rb', line 39
def reload
if @attributes[:id]
gist = @api.get_gist @attributes[:id]
elsif @attributes[:url]
gist = Githubris::Gist.new @api._get @attributes[:url]
else
raise Githubris::Error, 'Missing a unique identifier, such as an id or a url'
end
swap_attributes gist
end
|
#save ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/githubris/gist.rb', line 50
def save
if new?
saved_attributes = @api.post_gist(saving_attributes)
else
saved_attributes = @api.patch_gist(@attributes[:id], saving_attributes)
end
swap_attributes saved_attributes
end
|
#saving_attributes ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/githubris/gist.rb', line 59
def saving_attributes
{
:description => @attributes[:description],
:public => @attributes[:public],
:files => @attributes[:files]
}
end
|
#star! ⇒ Object
13
14
15
|
# File 'lib/githubris/gist.rb', line 13
def star!
@api.put_gist_star(@attributes[:id])
end
|
#starred? ⇒ Boolean
21
22
23
|
# File 'lib/githubris/gist.rb', line 21
def starred?
@api.get_gist_starred?(@attributes[:id])
end
|
#unstar! ⇒ Object
17
18
19
|
# File 'lib/githubris/gist.rb', line 17
def unstar!
@api.delete_gist_star(@attributes[:id])
end
|
#unstarred? ⇒ Boolean
25
26
27
|
# File 'lib/githubris/gist.rb', line 25
def unstarred?
!starred?
end
|
#user ⇒ Object
9
10
11
|
# File 'lib/githubris/gist.rb', line 9
def user
@user ||= Githubris::User.new(@attributes[:user])
end
|