gast 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc3ee213f4e5d86b1bc8a6dc8b6b4da7810421ed
4
- data.tar.gz: 2c68262859282689cf90740a7b537ecb3d27b8dd
3
+ metadata.gz: 91f1374024d46848fe452f840328d6e33b55baf6
4
+ data.tar.gz: ecbb056ed54a9a71f9d70b1c58ce4f523f8d917f
5
5
  SHA512:
6
- metadata.gz: 0886827a727068ae5cbc01049d8ad4ef534d4541be3fa7f0813d634a55351558d004482cf7e98dcad62c4b68bd233946b8302dee7b133a0b93fa85edc31e1da1
7
- data.tar.gz: 6af61f29398256d0df3985e9c0420623be58db8828db6900d1915f73b8ace6dc49cf978099b0ea6a355a445edced309ec92bef2cd15f8aedc45eaafb197153c2
6
+ metadata.gz: c1874b5081fafd14d9e82460b2defe9d4ab6558031fde3d21912c55da51bca072cc2e511b5665e8a6a10531a3a7b569c664eaeb023d7fa11ab4a07fa9b9f100c
7
+ data.tar.gz: 4d79c0d38b33f15577a71d651feb45f41c93864ebe7ed65c72c13c8d1f7a96d642d5c14383d142001684f017cf041b4afcf2279097335aecde71c95351cf26ca
data/Gemfile CHANGED
@@ -11,4 +11,5 @@ group :development do
11
11
  gem 'guard-rspec'
12
12
  gem 'pry'
13
13
  gem 'pry-remote'
14
+ gem 'rubocop'
14
15
  end
data/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
 
6
6
  memo application of using git.
7
7
 
8
+ ![screen shot v0.0.4](https://cloud.githubusercontent.com/assets/72997/3080641/a04ba064-e4b3-11e3-9e8c-8adecc8873e4.png)
9
+
8
10
  ## Installation
9
11
 
10
12
  Add this line to your application's Gemfile:
@@ -28,7 +30,7 @@ Or install it yourself as:
28
30
 
29
31
  ## Contributing
30
32
 
31
- 1. Fork it ( https://github.com/[my-github-username]/gast/fork )
33
+ 1. Fork it ( https://github.com/futoase/gast/fork )
32
34
  2. Create your feature branch (`git checkout -b my-new-feature`)
33
35
  3. Commit your changes (`git commit -am 'Add some feature'`)
34
36
  4. Push to the branch (`git push origin my-new-feature`)
data/config/path.yml ADDED
@@ -0,0 +1 @@
1
+ save_dir: '/tmp/gast'
data/gast.gemspec CHANGED
@@ -34,6 +34,4 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "rspec"
35
35
  spec.add_development_dependency "rack-test"
36
36
  spec.add_development_dependency "capybara"
37
- spec.add_development_dependency "pry"
38
- spec.add_development_dependency "pry-remote"
39
37
  end
data/lib/gast/app.rb CHANGED
@@ -2,7 +2,6 @@ require 'gast'
2
2
 
3
3
  module Gast
4
4
  class App < Sinatra::Base
5
-
6
5
  enable :method_override
7
6
  set :sprockets, Sprockets::Environment.new(root)
8
7
  set :assets_prefix, '/assets'
@@ -20,7 +19,7 @@ module Gast
20
19
  config.digest = digest_assets
21
20
  config.public_path = '/public'
22
21
 
23
- config.debug = true
22
+ config.debug = true
24
23
  end
25
24
 
26
25
  register Sinatra::Reloader
@@ -31,21 +30,19 @@ module Gast
31
30
  end
32
31
 
33
32
  before do
34
- @languages = YAML.load_file(
35
- File.expand_path('../../config/languages.yml', __dir__)
36
- )
33
+ @languages = Gast::LANGUAGES
37
34
  end
38
35
 
39
36
  before %r{/posts/\w+/(\w+)} do |id|
40
37
  unless /[a-zA-Z0-9]{30}/ =~ id.to_s
41
- halt haml(:error, locals: { message: "error is format of id" })
38
+ halt haml(:error, locals: { message: 'error is format of id' })
42
39
  end
43
40
  end
44
41
 
45
42
  not_found do
46
43
  haml :not_found
47
44
  end
48
-
45
+
49
46
  error do
50
47
  haml :error
51
48
  end
@@ -59,34 +56,34 @@ module Gast
59
56
  haml :list
60
57
  end
61
58
 
62
- get '/posts/view/:id' do
63
- @item = Gast::Memo.item(params[:id].to_s)
64
- @language = Gast::Memo.language(params[:id].to_s)
65
- @content_hash = params[:id].to_s
59
+ get '/posts/view/:content_id' do
60
+ @item = Gast::Memo.item(params[:content_id].to_s)
61
+ @language = Gast::Memo.language(params[:content_id].to_s)
62
+ @content_hash = params[:content_id].to_s
66
63
  haml :view
67
64
  end
68
65
 
69
- get '/posts/edit/:id' do
70
- @item = Gast::Memo.item(params[:id].to_s)
71
- @content_hash = params[:id].to_s
66
+ get '/posts/edit/:content_id' do
67
+ @item = Gast::Memo.item(params[:content_id].to_s)
68
+ @content_hash = params[:content_id].to_s
72
69
  haml :edit
73
70
  end
74
71
 
75
- put '/posts/update/:id' do
72
+ put '/posts/update/:content_id' do
76
73
  @result = Gast::Memo.update(
77
- id=params[:id].to_s,
78
- content=params[:content].to_s,
79
- language=params[:language].to_s
74
+ params[:content_id].to_s,
75
+ params[:content].to_s,
76
+ params[:language].to_s
80
77
  )
81
- redirect to("/posts/view/#{params[:id]}")
78
+ redirect to("/posts/view/#{params[:content_id]}")
82
79
  end
83
80
 
84
81
  post '/posts/new' do
85
82
  results = Gast::Memo.save(
86
- params[:content].to_s, params[:language].to_s
83
+ params[:content].to_s,
84
+ params[:language].to_s
87
85
  )
88
- redirect to("/posts/view/#{results[:id]}")
86
+ redirect to("/posts/view/#{results[:content_id]}")
89
87
  end
90
-
91
88
  end
92
89
  end
data/lib/gast/memo.rb CHANGED
@@ -1,30 +1,28 @@
1
1
  require 'gast'
2
2
 
3
3
  module Gast
4
-
5
4
  class Memo
6
-
7
- def self.save(content, language="no-highlight")
5
+ def self.save(content, language = 'no-highlight')
8
6
  @repo = Gast::Repository.new
9
7
  @repo.content = CGI.unescapeHTML(content.to_s)
10
8
  @repo.language = CGI.unescapeHTML(language.to_s)
11
9
  @repo.publish
12
10
  @repo.commit!
13
- {
14
- id: @repo.dir_name,
11
+ {
12
+ content_id: @repo.dir_name,
15
13
  language: language
16
14
  }
17
15
  end
18
16
 
19
- def self.update(id, content, language="no-highlight")
20
- return id if content.to_s.chomp == item(id).chomp
21
- @repo = Gast::Repository.new(id)
17
+ def self.update(content_id, content, language = 'no-highlight')
18
+ return content_id if content.to_s.chomp == item(content_id).chomp
19
+ @repo = Gast::Repository.new(content_id)
22
20
  @repo.content = CGI.unescapeHTML(content.to_s)
23
21
  @repo.language = CGI.unescapeHTML(language.to_s)
24
22
  @repo.publish
25
23
  @repo.commit!
26
- {
27
- id: @repo.dir_name,
24
+ {
25
+ content_id: @repo.dir_name,
28
26
  language: language
29
27
  }
30
28
  end
@@ -52,6 +50,5 @@ module Gast
52
50
  end
53
51
 
54
52
  def initialize; end
55
-
56
53
  end
57
54
  end
@@ -2,10 +2,10 @@ require 'gast'
2
2
 
3
3
  module Gast
4
4
  class Repository
5
-
6
5
  attr_reader :path, :dir_name
6
+ attr_writer :content, :language
7
7
 
8
- def initialize(dir_name=nil)
8
+ def initialize(dir_name = nil)
9
9
  if dir_name.nil?
10
10
  @dir_name = Digest::SHA512.new.update(rand.to_s).to_s[0..30]
11
11
  else
@@ -19,14 +19,6 @@ module Gast
19
19
  @git = Git.init(@path)
20
20
  end
21
21
 
22
- def content=(content)
23
- @content = content
24
- end
25
-
26
- def language=(language)
27
- @language = language.to_s
28
- end
29
-
30
22
  def publish
31
23
  save_content
32
24
  save_language
@@ -38,7 +30,7 @@ module Gast
38
30
 
39
31
  def save!
40
32
  @git.add(all: true)
41
- @git.commit_all("commit: #{DateTime.now.to_s}")
33
+ @git.commit_all("commit: #{DateTime.now}")
42
34
  end
43
35
 
44
36
  def commit!
@@ -49,22 +41,27 @@ module Gast
49
41
  private
50
42
 
51
43
  def create_dir
52
- unless File.exists?(@path)
53
- FileUtils.mkdir_p(@path)
54
- FileUtils.chmod(0755, @path)
55
- end
44
+ return unless File.exist?(@path)
45
+ FileUtils.mkdir_p(@path)
46
+ FileUtils.chmod(0755, @path)
56
47
  end
57
48
 
58
49
  def save_content
59
- path = File.expand_path(@path + "/content")
60
- open(path, 'w', 0644) { |io| io.write(@content) }
50
+ path = File.expand_path(@path + '/content')
51
+ open(path, 'w', 0644) do |io|
52
+ io.flock(File::LOCK_EX)
53
+ io.write(@content)
54
+ io.flock(File::LOCK_UN)
55
+ end
61
56
  end
62
57
 
63
58
  def save_language
64
59
  path = File.expand_path(@path + '/language')
65
- open(path, 'w', 0644) { |io| io.write(@language) }
60
+ open(path, 'w', 0644) do |io|
61
+ io.flock(File::LOCK_EX)
62
+ io.write(@language)
63
+ io.flock(File::LOCK_UN)
64
+ end
66
65
  end
67
-
68
66
  end
69
-
70
67
  end
data/lib/gast/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gast
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/gast.rb CHANGED
@@ -13,5 +13,13 @@ require 'cgi'
13
13
  require 'yaml'
14
14
 
15
15
  module Gast
16
- PATH = '/tmp/gast'
16
+ setting_of_path = YAML.load_file(
17
+ File.expand_path('../config/path.yml', __dir__)
18
+ )
19
+
20
+ PATH = setting_of_path['save_dir']
21
+
22
+ LANGUAGES = YAML.load_file(
23
+ File.expand_path('../config/languages.yml', __dir__)
24
+ )
17
25
  end
@@ -6,130 +6,120 @@ end
6
6
 
7
7
  describe Gast::App do
8
8
 
9
- let(:repo_dir) { File.expand_path("/tmp/gast") }
10
-
11
9
  after(:each) do
12
- FileUtils.rm_r(Dir.glob(repo_dir + '/**'), secure: true)
10
+ FileUtils.rm_r(Dir.glob(Gast::PATH + '/**'), secure: true)
13
11
  end
14
12
 
15
- let(:hello_world) { "Hello World" }
16
- let(:welcome_to_underground) { "Welcome to underground" }
13
+ let(:hello_world) { 'Hello World' }
14
+ let(:welcome_to_underground) { 'Welcome to underground' }
17
15
  let(:inline_html) { "<script>alert('Hello world!');</script>" }
18
16
  let(:sample_of_code_ruby) { get_fixture('sample_of_code.rb') }
19
17
 
20
- let(:view_path) { /.+\/posts\/view\/[a-z0-9]+/ }
18
+ let(:view_path) { %r{.+/posts/view/[a-z0-9]+} }
21
19
 
22
- it "should be get index" do
23
- get '/'
20
+ it 'should be get index' do
21
+ get '/'
24
22
  expect(last_response).to be_ok
25
23
  end
26
-
27
- it "should be get title of index" do
24
+
25
+ it 'should be get title of index' do
28
26
  get '/'
29
27
  expect(last_response.body).to match(/Gast/)
30
28
  end
31
29
 
32
- it "should be get error" do
30
+ it 'should be get error' do
33
31
  get '/hogehoge'
34
32
  expect(last_response).not_to be_ok
35
33
  end
36
34
 
37
- it "should be get list" do
35
+ it 'should be get list' do
38
36
  get '/posts/list'
39
37
  expect(last_response).to be_ok
40
38
  end
41
39
 
42
- it "should be save of content on git directory" do
43
- post '/posts/new', { content: hello_world }
40
+ it 'should be save of content on git directory' do
41
+ post('/posts/new', content: hello_world)
44
42
  expect(last_response.status).to eq 302
45
43
  expect(last_response.location).to match(view_path)
46
44
  end
47
45
 
48
- it "should be update content" do
49
- post '/posts/new', { content: hello_world }
50
-
46
+ it 'should be update content' do
47
+ post('/posts/new', content: hello_world)
48
+
51
49
  expect(last_response.status).to eq 302
52
50
  expect(last_response.location).to match(view_path)
53
51
 
54
- post '/posts/new', { content: welcome_to_underground }
52
+ post('/posts/new', content: welcome_to_underground)
55
53
  expect(last_response.status).to eq 302
56
54
  expect(last_response.location).to match(view_path)
57
55
  end
58
56
 
59
- it "should be view of item" do
60
- post '/posts/new', { content: hello_world }
61
-
62
- repository = File.expand_path(Dir.glob(repo_dir + '/**').first)
57
+ it 'should be view of item' do
58
+ post('/posts/new', content: hello_world)
63
59
 
64
- get "/posts/view/#{repository.split('/').last}"
60
+ get "/posts/view/#{dir_name_of_latest_repository}"
65
61
 
66
62
  expect(last_response).to be_ok
67
- expect(File.read(repository + '/content')).to eq hello_world
63
+ expect(latest_content).to eq hello_world
68
64
  end
69
65
 
70
- it "should be can update of item" do
71
- post '/posts/new', { content: hello_world }
66
+ it 'should be can update of item' do
67
+ post('/posts/new', content: hello_world)
72
68
 
73
- repository = File.expand_path(Dir.glob(repo_dir + '/**').first)
74
-
75
- get "/posts/view/#{repository.split('/').last}"
69
+ get "/posts/view/#{dir_name_of_latest_repository}"
76
70
 
77
71
  expect(last_response).to be_ok
78
72
 
79
- put "/posts/update/#{repository.split('/').last}", { content: welcome_to_underground }
80
- get "/posts/view/#{repository.split('/').last}"
73
+ put("/posts/update/#{dir_name_of_latest_repository}",
74
+ content: welcome_to_underground)
75
+ get "/posts/view/#{dir_name_of_latest_repository}"
81
76
 
82
77
  expect(last_response).to be_ok
83
78
 
84
- expect(File.read(repository + '/content')).to eq welcome_to_underground
79
+ expect(latest_content).to eq welcome_to_underground
85
80
  end
86
81
 
87
- it "should be get not found" do
88
- get "/posts/hoge"
82
+ it 'should be get not found' do
83
+ get '/posts/hoge'
89
84
 
90
85
  expect(last_response).not_to be_ok
91
86
  expect(last_response.status).to be 404
92
87
  expect(last_response.body).to match(/Not Found/)
93
88
  end
94
89
 
95
- it "should be get content is escaped by HTML" do
96
-
97
- post '/posts/new', { content: inline_html }
90
+ it 'should be get content is escaped by HTML' do
91
+ post('/posts/new', content: inline_html)
98
92
 
99
- repository = File.expand_path(Dir.glob(repo_dir + '/**').first)
93
+ expect(latest_content).to eq inline_html
100
94
 
101
- expect(File.read(repository + '/content')).to eq inline_html
102
-
103
- get "/posts/view/#{repository.split('/').last}"
95
+ get "/posts/view/#{dir_name_of_latest_repository}"
104
96
 
105
97
  expect(last_response).to be_ok
106
98
  expect(last_response.body).to include(CGI.escapeHTML(inline_html))
107
-
108
99
  end
109
100
 
110
- it "should be post language type the code highlight" do
111
- post '/posts/new', { content: sample_of_code_ruby, language: "ruby" }
112
- repository = File.expand_path(Dir.glob(repo_dir + '/**').first)
101
+ it 'should be post language type the code highlight' do
102
+ post('/posts/new', content: sample_of_code_ruby, language: 'ruby')
113
103
 
114
- expect(File.read(repository + '/content')).to eq sample_of_code_ruby
115
- expect(File.read(repository + '/language')).to eq "ruby"
104
+ expect(latest_content).to eq sample_of_code_ruby
105
+ expect(latest_language_of_content).to eq 'ruby'
116
106
 
117
- get "/posts/view/#{repository.split('/').last}"
107
+ get "/posts/view/#{dir_name_of_latest_repository}"
118
108
 
119
109
  expect(last_response).to be_ok
120
110
  end
121
111
 
122
- it "should be succeeded change of language type" do
123
- post '/posts/new', { content: sample_of_code_ruby, language: "ruby" }
124
- repository = File.expand_path(Dir.glob(repo_dir + '/**').first)
112
+ it 'should be succeeded change of language type' do
113
+ post('/posts/new', content: sample_of_code_ruby, language: 'ruby')
125
114
 
126
- expect(File.read(repository + '/content')).to eq sample_of_code_ruby
127
- expect(File.read(repository + '/language')).to eq "ruby"
115
+ expect(latest_content).to eq sample_of_code_ruby
116
+ expect(latest_language_of_content).to eq 'ruby'
128
117
 
129
- put "/posts/update/#{repository.split('/').last}", { content: sample_of_code_ruby, language: "python" }
118
+ put("/posts/update/#{dir_name_of_latest_repository}",
119
+ content: sample_of_code_ruby, language: 'python')
130
120
 
131
- expect(File.read(repository + '/content')).to eq sample_of_code_ruby
132
- expect(File.read(repository + '/language')).to eq "python"
121
+ expect(latest_content).to eq sample_of_code_ruby
122
+ expect(latest_language_of_content).to eq 'python'
133
123
  end
134
124
 
135
125
  end
data/spec/memo_spec.rb CHANGED
@@ -1,23 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Gast::Memo do
4
+ let(:welcome_to_underground) { 'Welcome to underground' }
4
5
 
5
- def repo_path(num)
6
- File.expand_path("/tmp/gast/#{num}")
6
+ after(:each) do
7
+ FileUtils.rm_r(Dir.glob(Gast::PATH + '/**'), secure: true)
7
8
  end
8
9
 
9
- def repo_dir
10
- '/tmp/gast'
11
- end
12
-
13
- let(:welcome_to_underground) { "Welcome to underground" }
14
-
15
- after(:each) {
16
- FileUtils.rm_r(Dir.glob(repo_dir + '/**'), secure: true)
17
- }
18
-
19
- it "should be get list of directory" do
20
- 0.upto(9) do |i|
10
+ it 'should be get list of directory' do
11
+ 10.times do |i|
21
12
  Gast::Memo.save(welcome_to_underground)
22
13
  end
23
14
  expect(Gast::Memo.number).to eq 10
@@ -6,39 +6,35 @@ describe Gast::Repository do
6
6
 
7
7
  let(:git) { Git.init(repo.path) }
8
8
 
9
- let(:repo_path) { File.expand_path("/tmp/gast/1") }
9
+ let(:user_content) { 'Hello World' }
10
+ let(:selected_language) { 'ruby' }
10
11
 
11
- let(:repo_dir) { "/tmp/gast" }
12
-
13
- let(:user_content) { "Hello World" }
14
- let(:selected_language) { "ruby" }
15
-
16
- before(:each) {
12
+ before(:each) do
17
13
  repo.content = user_content
18
14
  repo.language = selected_language
19
15
  repo.publish
20
16
  repo.commit!
21
- }
17
+ end
22
18
 
23
- after(:each) {
24
- FileUtils.rm_r(Dir.glob(repo_dir + '/**'), secure: true)
25
- }
19
+ after(:each) do
20
+ FileUtils.rm_r(Dir.glob(Gast::PATH + '/**'), secure: true)
21
+ end
26
22
 
27
- it "should be create of repository" do
23
+ it 'should be create of repository' do
28
24
  expect(FileTest.exists?(repo.path)).to be_true
29
25
  end
30
26
 
31
- it "should be content is a Hello world" do
32
- expect(File.read(repo.path + '/content')).to eq user_content
27
+ it 'should be content is a Hello world' do
28
+ expect(latest_content).to eq user_content
33
29
  end
34
30
 
35
- it "should be language is a ruby" do
36
- expect(File.read(repo.path + '/language')).to eq selected_language
31
+ it 'should be language is a ruby' do
32
+ expect(latest_language_of_content).to eq selected_language
37
33
  end
38
34
 
39
- it "should be save of commit message is correct" do
35
+ it 'should be save of commit message is correct' do
40
36
  Timecop.freeze
41
- expect(git.log.first.message).to eq "commit: #{DateTime.now.to_s}"
37
+ expect(git.log.first.message).to eq "commit: #{DateTime.now}"
42
38
  Timecop.return
43
39
  end
44
40
 
data/spec/spec_helper.rb CHANGED
@@ -49,3 +49,19 @@ end
49
49
  def get_languages
50
50
  YAML.load_file(File.expand_path('../config/languages.yml', __dir__))
51
51
  end
52
+
53
+ def latest_repository
54
+ File.expand_path(Dir.glob(Gast::PATH + '/**').first)
55
+ end
56
+
57
+ def dir_name_of_latest_repository
58
+ latest_repository.split('/').last
59
+ end
60
+
61
+ def latest_content
62
+ File.read(latest_repository + '/content')
63
+ end
64
+
65
+ def latest_language_of_content
66
+ File.read(latest_repository + '/language')
67
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - futoase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-25 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -220,34 +220,6 @@ dependencies:
220
220
  - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
- - !ruby/object:Gem::Dependency
224
- name: pry
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - ">="
228
- - !ruby/object:Gem::Version
229
- version: '0'
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - ">="
235
- - !ruby/object:Gem::Version
236
- version: '0'
237
- - !ruby/object:Gem::Dependency
238
- name: pry-remote
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - ">="
242
- - !ruby/object:Gem::Version
243
- version: '0'
244
- type: :development
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - ">="
249
- - !ruby/object:Gem::Version
250
- version: '0'
251
223
  description: memo application of using git
252
224
  email:
253
225
  - futoase@gmail.com
@@ -267,6 +239,7 @@ files:
267
239
  - bin/gast
268
240
  - config.ru
269
241
  - config/languages.yml
242
+ - config/path.yml
270
243
  - gast.gemspec
271
244
  - lib/gast.rb
272
245
  - lib/gast/app.rb