octonore 0.0.2 → 0.0.3
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 +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -5
- data/README.md +43 -7
- data/VERSION +1 -1
- data/lib/octonore/template.rb +21 -15
- data/octonore.gemspec +6 -6
- data/spec/fixtures/octonore_cassettes/template.yml +83 -13
- data/spec/lib/octonore/template_spec.rb +17 -23
- data/spec/spec_helper.rb +3 -0
- metadata +3 -2
- data/Gemfile.lock +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07233694c096c366e80590fcdf3f1b1f939eb635
|
4
|
+
data.tar.gz: 7b77b9903b047452ec932f2002672341497470db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e0f37b5874a1205f734eb1dfe55ff0e8481f4ca627b9afdf3b72b969cfc9fb9ecacffde7db991fd1b7777b9dc4e95498c816aeaa685551d1ad0fa6194dd73a7
|
7
|
+
data.tar.gz: 019e9604fd33ecba86a11f757ccbb64e0dbb72bfe6c0bdd8e2bd5b3998800255ffb5c5577489f55877bb3a9a767ad70ac0c30ad3d4a898ce59f3cfc9aa7fdae5
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'httparty'
|
3
|
+
gem 'httparty', '~> 0.11.0'
|
4
4
|
|
5
5
|
group :test do
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem
|
9
|
-
gem
|
6
|
+
gem "rspec", "~> 2.13.0"
|
7
|
+
gem "webmock", "~> 1.11.0"
|
8
|
+
gem "vcr", "~> 2.5.0"
|
9
|
+
gem "rake", "~> 10.0.4"
|
10
|
+
gem "coveralls", "~> 0.6.7", require: false
|
10
11
|
end
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
Octonore
|
1
|
+
Octonore [](https://travis-ci.org/zachlatta/octonore) [](https://codeclimate.com/github/zachlatta/octonore) [](https://coveralls.io/r/zachlatta/octonore?branch=master) [](https://gemnasium.com/zachlatta/octonore)
|
2
2
|
========
|
3
3
|
|
4
4
|
An octolicious wrapper around the [Gitignore templates API](http://developer.github.com/v3/gitignore/).
|
5
5
|
|
6
|
-
|
6
|
+
$ gem install octonore
|
7
7
|
|
8
8
|
|
9
9
|
Usage
|
@@ -11,10 +11,46 @@ Usage
|
|
11
11
|
|
12
12
|
To get a gitignore template you first need to instantiate it.
|
13
13
|
|
14
|
-
|
15
|
-
=> #<Octonore::Template:
|
14
|
+
>> c_template = Octonore::Template.new('C')
|
15
|
+
=> #<Octonore::Template:0x007fe65b8b2420 @name="C", @source="# Object files\n*.
|
16
|
+
o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Windows DLLs)\n*.dll\n*.
|
17
|
+
so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n">
|
16
18
|
|
17
|
-
To get
|
19
|
+
To get the template's source code, you can call its `source` accessor.
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
>> c_template.source
|
22
|
+
=> "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Wi
|
23
|
+
ndows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app
|
24
|
+
\n"
|
25
|
+
|
26
|
+
|
27
|
+
You can also get the template's name with the `name` accessor.
|
28
|
+
|
29
|
+
>> c_template.name
|
30
|
+
=> "C"
|
31
|
+
|
32
|
+
You can reload the template's source from Github with the `update` method.
|
33
|
+
|
34
|
+
>> c_template.update
|
35
|
+
=> "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Wi
|
36
|
+
ndows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app
|
37
|
+
\n"
|
38
|
+
|
39
|
+
|
40
|
+
### Example Program
|
41
|
+
|
42
|
+
The following program asks the user for the name of a gitignore template. It then writes the gitignore to a file ending in `.gitignore`. If the user enters `Java`, then it will write the Java gitignore template to `java.gitignore` in the current directory.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require 'octonore'
|
46
|
+
|
47
|
+
begin
|
48
|
+
print "Enter the name of a gitignore template (case sensitive): "
|
49
|
+
template = Octonore::Template.new(gets.strip)
|
50
|
+
|
51
|
+
File.open("#{template.name.downcase}.gitignore", 'w') { |file|
|
52
|
+
file.write(template.source) }
|
53
|
+
rescue GitignoreTemplateNotFoundError => e
|
54
|
+
puts e.message
|
55
|
+
end
|
56
|
+
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/octonore/template.rb
CHANGED
@@ -3,7 +3,7 @@ module Octonore
|
|
3
3
|
# A gitignore template. Templates consist of a name and source.
|
4
4
|
class Template
|
5
5
|
|
6
|
-
attr_accessor :name
|
6
|
+
attr_accessor :name, :source
|
7
7
|
|
8
8
|
include HTTParty
|
9
9
|
|
@@ -11,7 +11,7 @@ module Octonore
|
|
11
11
|
|
12
12
|
base_uri 'https://api.github.com/gitignore'
|
13
13
|
|
14
|
-
# Create a new template
|
14
|
+
# Create a new template.
|
15
15
|
#
|
16
16
|
# Example:
|
17
17
|
# c_template = Octonore::Template.new('C')
|
@@ -22,21 +22,20 @@ module Octonore
|
|
22
22
|
|
23
23
|
def initialize(name)
|
24
24
|
self.name = name
|
25
|
+
update
|
25
26
|
end
|
26
27
|
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def data(force = false)
|
39
|
-
force ? @data = get_data : @data ||= get_data
|
28
|
+
# Update the Gitignore source from Github.
|
29
|
+
|
30
|
+
def update
|
31
|
+
data = get_data
|
32
|
+
|
33
|
+
if valid_template_hash? data
|
34
|
+
@source = data["source"]
|
35
|
+
else
|
36
|
+
raise GitignoreTemplateNotFoundError,
|
37
|
+
"Template '#{@name}' does not exist!"
|
38
|
+
end
|
40
39
|
end
|
41
40
|
|
42
41
|
|
@@ -46,10 +45,17 @@ module Octonore
|
|
46
45
|
self.class.get "/templates/#{self.name}", headers: headers
|
47
46
|
end
|
48
47
|
|
48
|
+
def valid_template_hash?(template_hash)
|
49
|
+
template_hash["message"] != "Not Found"
|
50
|
+
end
|
51
|
+
|
49
52
|
def headers
|
50
53
|
{"User-Agent" => USER_AGENT}
|
51
54
|
end
|
52
55
|
|
53
56
|
end
|
54
57
|
|
58
|
+
class GitignoreTemplateNotFoundError < StandardError
|
59
|
+
end
|
60
|
+
|
55
61
|
end
|
data/octonore.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'octonore'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.3'
|
4
4
|
s.date = '2013-05-23'
|
5
|
-
s.summary =
|
6
|
-
s.description =
|
7
|
-
API.
|
5
|
+
s.summary = 'Wrapper around the Github gitignore template API.'
|
6
|
+
s.description = 'An octolicious wrapper around the Github gitignore template
|
7
|
+
API.'
|
8
8
|
s.license = 'MIT'
|
9
9
|
|
10
|
-
s.authors = [
|
10
|
+
s.authors = ['Zach Latta']
|
11
11
|
s.email = 'zchlatta@gmail.com'
|
12
12
|
s.homepage = 'http://rubygems.org/gems/octonore'
|
13
13
|
|
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f|
|
17
17
|
File.basename(f)
|
18
18
|
}
|
19
|
-
s.require_paths = [
|
19
|
+
s.require_paths = ['lib']
|
20
20
|
end
|
@@ -2,31 +2,56 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://api.github.com/gitignore/
|
5
|
+
uri: https://api.github.com/gitignore/templates/C
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
9
|
-
headers:
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- octocore/0.11.0
|
10
12
|
response:
|
11
13
|
status:
|
12
|
-
code:
|
13
|
-
message:
|
14
|
+
code: 200
|
15
|
+
message: OK
|
14
16
|
headers:
|
15
17
|
Server:
|
16
18
|
- GitHub.com
|
17
19
|
Date:
|
18
|
-
-
|
20
|
+
- Fri, 24 May 2013 01:15:28 GMT
|
19
21
|
Content-Type:
|
20
|
-
- application/
|
21
|
-
Content-Length:
|
22
|
-
- '107'
|
22
|
+
- application/json; charset=utf-8
|
23
23
|
Connection:
|
24
24
|
- keep-alive
|
25
|
+
Status:
|
26
|
+
- 200 OK
|
27
|
+
X-Ratelimit-Limit:
|
28
|
+
- '60'
|
29
|
+
X-Ratelimit-Remaining:
|
30
|
+
- '49'
|
31
|
+
X-Github-Media-Type:
|
32
|
+
- github.beta; format=json
|
33
|
+
X-Content-Type-Options:
|
34
|
+
- nosniff
|
35
|
+
Content-Length:
|
36
|
+
- '180'
|
37
|
+
Access-Control-Allow-Credentials:
|
38
|
+
- 'true'
|
39
|
+
Access-Control-Expose-Headers:
|
40
|
+
- ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-OAuth-Scopes, X-Accepted-OAuth-Scopes
|
41
|
+
Access-Control-Allow-Origin:
|
42
|
+
- '*'
|
43
|
+
Etag:
|
44
|
+
- '"547a43504d718cb7bc42ed51aae7f643"'
|
45
|
+
Cache-Control:
|
46
|
+
- max-age=0, private, must-revalidate
|
47
|
+
Vary:
|
48
|
+
- Accept-Encoding
|
25
49
|
body:
|
26
50
|
encoding: UTF-8
|
27
|
-
string: '{"
|
51
|
+
string: '{"name":"C","source":"# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n#
|
52
|
+
Shared objects (inc. Windows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n"}'
|
28
53
|
http_version:
|
29
|
-
recorded_at:
|
54
|
+
recorded_at: Fri, 24 May 2013 01:15:29 GMT
|
30
55
|
- request:
|
31
56
|
method: get
|
32
57
|
uri: https://api.github.com/gitignore/templates/C
|
@@ -44,7 +69,7 @@ http_interactions:
|
|
44
69
|
Server:
|
45
70
|
- GitHub.com
|
46
71
|
Date:
|
47
|
-
-
|
72
|
+
- Fri, 24 May 2013 01:15:29 GMT
|
48
73
|
Content-Type:
|
49
74
|
- application/json; charset=utf-8
|
50
75
|
Connection:
|
@@ -54,7 +79,7 @@ http_interactions:
|
|
54
79
|
X-Ratelimit-Limit:
|
55
80
|
- '60'
|
56
81
|
X-Ratelimit-Remaining:
|
57
|
-
- '
|
82
|
+
- '48'
|
58
83
|
X-Github-Media-Type:
|
59
84
|
- github.beta; format=json
|
60
85
|
X-Content-Type-Options:
|
@@ -78,5 +103,50 @@ http_interactions:
|
|
78
103
|
string: '{"name":"C","source":"# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n#
|
79
104
|
Shared objects (inc. Windows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n"}'
|
80
105
|
http_version:
|
81
|
-
recorded_at:
|
106
|
+
recorded_at: Fri, 24 May 2013 01:15:29 GMT
|
107
|
+
- request:
|
108
|
+
method: get
|
109
|
+
uri: https://api.github.com/gitignore/templates/invalid
|
110
|
+
body:
|
111
|
+
encoding: US-ASCII
|
112
|
+
string: ''
|
113
|
+
headers:
|
114
|
+
User-Agent:
|
115
|
+
- octocore/0.11.0
|
116
|
+
response:
|
117
|
+
status:
|
118
|
+
code: 404
|
119
|
+
message: Not Found
|
120
|
+
headers:
|
121
|
+
Server:
|
122
|
+
- GitHub.com
|
123
|
+
Date:
|
124
|
+
- Fri, 24 May 2013 01:15:29 GMT
|
125
|
+
Content-Type:
|
126
|
+
- application/json; charset=utf-8
|
127
|
+
Connection:
|
128
|
+
- keep-alive
|
129
|
+
Status:
|
130
|
+
- 404 Not Found
|
131
|
+
X-Ratelimit-Limit:
|
132
|
+
- '60'
|
133
|
+
X-Ratelimit-Remaining:
|
134
|
+
- '47'
|
135
|
+
X-Github-Media-Type:
|
136
|
+
- github.beta; format=json
|
137
|
+
X-Content-Type-Options:
|
138
|
+
- nosniff
|
139
|
+
Content-Length:
|
140
|
+
- '23'
|
141
|
+
Access-Control-Allow-Credentials:
|
142
|
+
- 'true'
|
143
|
+
Access-Control-Expose-Headers:
|
144
|
+
- ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-OAuth-Scopes, X-Accepted-OAuth-Scopes
|
145
|
+
Access-Control-Allow-Origin:
|
146
|
+
- '*'
|
147
|
+
body:
|
148
|
+
encoding: UTF-8
|
149
|
+
string: '{"message":"Not Found"}'
|
150
|
+
http_version:
|
151
|
+
recorded_at: Fri, 24 May 2013 01:15:29 GMT
|
82
152
|
recorded_with: VCR 2.5.0
|
@@ -18,10 +18,18 @@ describe Octonore::Template do
|
|
18
18
|
|
19
19
|
let(:template) { Octonore::Template.new('C') }
|
20
20
|
|
21
|
+
before { VCR.insert_cassette 'template', :record => :new_episodes }
|
22
|
+
|
23
|
+
after { VCR.eject_cassette }
|
24
|
+
|
21
25
|
it "should have a name attribute" do
|
22
26
|
template.should respond_to :name
|
23
27
|
end
|
24
28
|
|
29
|
+
it "should have a source attribute" do
|
30
|
+
template.should respond_to :source
|
31
|
+
end
|
32
|
+
|
25
33
|
it "should have the right name" do
|
26
34
|
template.name.should eq('C')
|
27
35
|
end
|
@@ -36,35 +44,21 @@ describe Octonore::Template do
|
|
36
44
|
|
37
45
|
after { VCR.eject_cassette }
|
38
46
|
|
39
|
-
it "should have
|
40
|
-
template.should respond_to :
|
47
|
+
it "should have an update method" do
|
48
|
+
template.should respond_to :update
|
41
49
|
end
|
42
50
|
|
43
|
-
it "should
|
44
|
-
template.
|
51
|
+
it "should be able to refresh data from Github" do
|
52
|
+
template.source = nil
|
53
|
+
template.update
|
54
|
+
template.source.should_not equal nil
|
45
55
|
end
|
46
56
|
|
47
|
-
it "should
|
48
|
-
|
57
|
+
it "should raise an error if template doesn't exist" do
|
58
|
+
expect {
|
59
|
+
bad_template = Octonore::Template.new('invalid') }.to raise_error
|
49
60
|
end
|
50
61
|
|
51
|
-
describe "caching" do
|
52
|
-
|
53
|
-
before do
|
54
|
-
template.data
|
55
|
-
stub_request(:any, /api.github.com/).to_timeout
|
56
|
-
end
|
57
|
-
|
58
|
-
it "must cache the data" do
|
59
|
-
template.data.should be_instance_of Hash
|
60
|
-
end
|
61
|
-
|
62
|
-
it "must refresh the data if forced" do
|
63
|
-
lambda { template.data(true) }.should raise_error Timeout::Error
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
62
|
end
|
69
63
|
|
70
64
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octonore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Latta
|
@@ -18,9 +18,10 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- .coveralls.yml
|
21
22
|
- .gitignore
|
23
|
+
- .travis.yml
|
22
24
|
- Gemfile
|
23
|
-
- Gemfile.lock
|
24
25
|
- LICENSE
|
25
26
|
- README.md
|
26
27
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
addressable (2.3.4)
|
5
|
-
crack (0.3.2)
|
6
|
-
diff-lcs (1.2.4)
|
7
|
-
httparty (0.11.0)
|
8
|
-
multi_json (~> 1.0)
|
9
|
-
multi_xml (>= 0.5.2)
|
10
|
-
multi_json (1.7.3)
|
11
|
-
multi_xml (0.5.3)
|
12
|
-
rake (10.0.4)
|
13
|
-
rspec (2.13.0)
|
14
|
-
rspec-core (~> 2.13.0)
|
15
|
-
rspec-expectations (~> 2.13.0)
|
16
|
-
rspec-mocks (~> 2.13.0)
|
17
|
-
rspec-core (2.13.1)
|
18
|
-
rspec-expectations (2.13.0)
|
19
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
20
|
-
rspec-mocks (2.13.1)
|
21
|
-
vcr (2.5.0)
|
22
|
-
webmock (1.11.0)
|
23
|
-
addressable (>= 2.2.7)
|
24
|
-
crack (>= 0.3.2)
|
25
|
-
|
26
|
-
PLATFORMS
|
27
|
-
ruby
|
28
|
-
|
29
|
-
DEPENDENCIES
|
30
|
-
httparty
|
31
|
-
rake
|
32
|
-
rspec
|
33
|
-
vcr
|
34
|
-
webmock
|