cheatly 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/cheatly/sheet.rb +30 -3
- data/lib/cheatly/version.rb +1 -1
- data/lib/cheatly.rb +16 -5
- data/sheets/help.yml +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWE4Y2MzYzU2MGNhMTE3YzAxN2E5N2JkOGVmODBkNmZkY2VlZWZiNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGZiNTAzZDEyMmNlNmE5NmVjYTkwZDAxZTZhYTEyYWFiODQ3NDdlNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjJiZDgyY2RkMDMxMDdlMjNkOTYzNjdkZjJhZjM5Njc5YmRkNDNjZjI2ZGI0
|
10
|
+
N2FlYWQxZTc2Mjg5MThjNjc5NGZjYTIxMmE0ZmQ1ZDYwY2YzOTk0ZGJjZDQy
|
11
|
+
MDFiODFmYzU0Y2VkNzQyNTYzZGJhNzgxYWY2M2VkMGY2YzY2OTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmI1ZTE2NjE3MDFmYjk5ZWEyNWQyNjdhYTI0MTc2NjA3ZjFkY2NiMGFhZjZk
|
14
|
+
NmMyZTFhNGJhOTFlNmMxNGIxMzI1YTQwNTEyMTgwZThiYWU0YjlkYTIxZDVi
|
15
|
+
ZTM2NGRiNDYyODA0ZmU5MGI4OTNlMzA2YTU3NzU1OTYxNDQ5MDI=
|
data/lib/cheatly/sheet.rb
CHANGED
@@ -1,21 +1,37 @@
|
|
1
1
|
module Cheatly
|
2
2
|
class Sheet
|
3
3
|
attr_accessor :title, :body
|
4
|
-
|
4
|
+
|
5
|
+
def initialize(title, body = nil, options = {})
|
5
6
|
@title, @body = title, body
|
7
|
+
@presisted = options[:persisted] || false
|
6
8
|
end
|
7
9
|
|
8
10
|
def to_s
|
9
11
|
" #{@body.gsub("\r",'').gsub("\n", "\n ")}"
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
14
|
+
def create
|
13
15
|
adapter.create(title, body)
|
14
16
|
end
|
15
17
|
|
18
|
+
def update
|
19
|
+
adapter.update(title, body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def save
|
23
|
+
if @persisted
|
24
|
+
update
|
25
|
+
else
|
26
|
+
create
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
16
30
|
def self.find(handle)
|
17
31
|
t, b = adapter.find(handle)
|
18
|
-
Sheet.new(t, b)
|
32
|
+
Sheet.new(t, b, persisted: true)
|
33
|
+
rescue ## TODO: this is bad, fix me
|
34
|
+
nil
|
19
35
|
end
|
20
36
|
|
21
37
|
def self.all
|
@@ -31,6 +47,12 @@ module Cheatly
|
|
31
47
|
@adapter = FileAdapter.new
|
32
48
|
self
|
33
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def adapter
|
54
|
+
self.class.adapter
|
55
|
+
end
|
34
56
|
end
|
35
57
|
|
36
58
|
class FileAdapter
|
@@ -51,6 +73,11 @@ module Cheatly
|
|
51
73
|
f.write(body)
|
52
74
|
f.close
|
53
75
|
end
|
76
|
+
|
77
|
+
def update(name, body)
|
78
|
+
File.delete "sheets/#{name}.yml"
|
79
|
+
create(name, body)
|
80
|
+
end
|
54
81
|
end
|
55
82
|
|
56
83
|
class GithubAdapter
|
data/lib/cheatly/version.rb
CHANGED
data/lib/cheatly.rb
CHANGED
@@ -41,6 +41,10 @@ module Cheatly
|
|
41
41
|
|
42
42
|
def sheet(handle)
|
43
43
|
sheet = model.find(handle)
|
44
|
+
unless sheet
|
45
|
+
puts "Sheet not found, run 'cheatly list' to see the availables."
|
46
|
+
return
|
47
|
+
end
|
44
48
|
page
|
45
49
|
puts "#{sheet.title}:"
|
46
50
|
puts sheet.to_s
|
@@ -56,13 +60,18 @@ module Cheatly
|
|
56
60
|
end
|
57
61
|
|
58
62
|
def create(handle)
|
59
|
-
|
60
|
-
|
63
|
+
sheet = Sheet.with_file_adapter.new(handle)
|
64
|
+
sheet.body = write_to_tempfile(handle)
|
65
|
+
sheet.save
|
66
|
+
end
|
67
|
+
|
68
|
+
def edit(handle)
|
69
|
+
sheet = Sheet.with_file_adapter.find(handle)
|
70
|
+
sheet.body = write_to_tempfile(handle, sheet.body)
|
71
|
+
sheet.save
|
61
72
|
end
|
62
73
|
|
63
74
|
def write_to_tempfile(title, body = nil)
|
64
|
-
# god dammit i hate tempfile, this is so messy but i think it's
|
65
|
-
# the only way.
|
66
75
|
tempfile = Tempfile.new(title + '.yml')
|
67
76
|
tempfile.write(body) if body
|
68
77
|
tempfile.close
|
@@ -85,8 +94,10 @@ module Cheatly
|
|
85
94
|
list
|
86
95
|
when "new"
|
87
96
|
create(@handle)
|
97
|
+
when "edit"
|
98
|
+
edit(@handle)
|
88
99
|
else
|
89
|
-
puts "Command [#{@command}] not found
|
100
|
+
puts "Command [#{@command}] not found :-( . You can try running 'cheatly list' to check the available commands. "
|
90
101
|
end
|
91
102
|
end
|
92
103
|
end
|
data/sheets/help.yml
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheatly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arthur Neves
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- sheets/bash.yml
|
89
89
|
- sheets/exceptions.yml
|
90
90
|
- sheets/gem_release.yml
|
91
|
+
- sheets/help.yml
|
91
92
|
- sheets/migrations.yml
|
92
93
|
- sheets/sprintf.yml
|
93
94
|
- sheets/status_codes.yml
|