gollum_rails 1.5.12 → 1.5.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmY0ZTZlZDNhZDQxZjBiM2YzNzM1NGM5ZTg3NWEzYWY4OTY4MzExNA==
4
+ ZDJiNDIyYWE3Y2MyODMxOTk0NmFkNGFjMzBiYzc0NWI5NDlmNzg2OQ==
5
5
  data.tar.gz: !binary |-
6
- NmNhY2FjODc1YTQ4MThmMDRlNDZhZjliY2Y2NTAzODgyMjY2MTM3Yg==
6
+ YWM3YmM3M2VmNTk0YWQ2MTA5ZTRjNWU0ZjJkMjQ5NTYyOTg2ZmVlYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjM5NzEyODg1MWEzZWFlNjg4ZDU0MTdlZDRhODQ0NzlhNDg1ZjUxOWQ0ZDIw
10
- NTIzMjU1YjYxZWVlMDI5N2VhMTQ5YzIzMGMxN2VhZGYwYTU3ZDAyODg3N2Vm
11
- OTg1NTU3MWMxMjdkZWFjMWI5MzkwZDdhZGQ4Nzg4ODUxNjdjODE=
9
+ NGRmNmViZDg3M2JjYjBjMTMzMDM2MmMzYjFiNmM1NDYwNmJlNjMyNTA5ODNi
10
+ ZDEzN2VlMWEyYzVlMGE0NTA3OTEyYmQ3NzNjYjIzNDlhNjgzNmU2NjZjNWM0
11
+ OWQwY2QwMmMxNjFlN2VlNjIzZjg4NTA0Y2YyNTIwNTMxNTYyYWI=
12
12
  data.tar.gz: !binary |-
13
- OWY3NDkyNjdmMmUzZTdmMDAxYjVmMzVlMGFhYjhhOTBjZjAwY2Y1NjBlYWIx
14
- YmY3NWFhNWZhZTdiZmFiMmY2YTU1YjkwNDllZTZmM2MxZGQ4NTZjOTVlMzgy
15
- MmNjMjA5MjJkYjE2Mzc0ZDAzMzEyMzU0ZTYwNzM4Nzg2YmZjNzE=
13
+ YzAyMTUxZDZmMGQxMmI3YjI4NzExZGE1MjBkMjliNjczZjQzYjk0YzIzMjA2
14
+ OTYyMmQ3NTE5ODdlYTkwZjlkZGMwYzdjYjMwZGNlYzc0MjNhMjVmOTc2ZWIz
15
+ NWFmZDU3NDZiMDdlODM2NmVjZjcwMjBiODExMmUyODNmNDE3NDU=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gollum_rails (1.5.12)
4
+ gollum_rails (1.5.13)
5
5
  activemodel (>= 3.2.11)
6
6
  activesupport (>= 3.2.11)
7
7
  gollum-lib (~> 3.0.0)
data/gollum_rails.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.name = 'gollum_rails'
5
5
  s.rubyforge_project = s.name
6
6
 
7
- s.version = '1.5.12'
7
+ s.version = '1.5.13'
8
8
 
9
9
  s.summary = 'Combines Gollum and Rails'
10
10
  s.description= 'include Gollum into Rails with ease'
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  lib/generators/gollum_rails/model/model_generator.rb
46
46
  lib/generators/gollum_rails/model/templates/model_template.erb
47
47
  lib/gollum_rails.rb
48
+ lib/gollum_rails/attributes.rb
48
49
  lib/gollum_rails/callbacks.rb
49
50
  lib/gollum_rails/core.rb
50
51
  lib/gollum_rails/error.rb
@@ -57,17 +58,24 @@ Gem::Specification.new do |s|
57
58
  lib/gollum_rails/setup/error.rb
58
59
  lib/gollum_rails/setup/options.rb
59
60
  lib/gollum_rails/store.rb
61
+ lib/gollum_rails/upload.rb
62
+ lib/gollum_rails/upload/class_definitions.rb
63
+ lib/gollum_rails/upload/file_too_big_error.rb
60
64
  lib/gollum_rails/validation.rb
61
65
  spec/factories.rb
62
66
  spec/gollum_rails/page_core_spec.rb
63
67
  spec/gollum_rails/page_spec.rb
64
68
  spec/gollum_rails/respository_spec.rb
65
69
  spec/gollum_rails/setup_spec.rb
70
+ spec/gollum_rails/upload/class_definitions_spec.rb
71
+ spec/gollum_rails/upload_spec.rb
66
72
  spec/gollum_rails/wiki_spec.rb
67
73
  spec/spec_helper.rb
68
74
  spec/support/default_commit.rb
69
75
  spec/support/gollum_page_spec.rb
76
+ spec/support/sample_upload.rb
70
77
  spec/support/special_commit.rb
78
+ uploads/GLD-LOTR-2T.jpg
71
79
  ]
72
80
  # = MANIFEST =
73
81
 
data/lib/gollum_rails.rb CHANGED
@@ -31,17 +31,21 @@ module GollumRails
31
31
  autoload :Persistance
32
32
  autoload :Callbacks
33
33
  autoload :Error
34
+ autoload :Attributes
34
35
  autoload :Core
35
36
  autoload :Store
36
37
  autoload :Validation
37
38
  autoload :Finders
39
+
38
40
  autoload :Page
41
+ autoload :Upload
42
+
39
43
  autoload :Setup
40
44
  autoload :Orm
41
45
  autoload :Meta
42
46
 
43
47
  # GollumRails version
44
- VERSION = '1.5.12'
48
+ VERSION = '1.5.13'
45
49
 
46
50
  end
47
51
 
@@ -0,0 +1,33 @@
1
+ module GollumRails
2
+ module Attributes
3
+ extend ActiveSupport::Concern
4
+
5
+ # Allows you to set all the attributes by passing in a hash of attributes with
6
+ # keys matching the attribute name
7
+ #
8
+ # new_attributes - Hash - Hash of arguments
9
+ def assign_attributes(new_attributes)
10
+ if !new_attributes.respond_to?(:stringify_keys)
11
+ raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."
12
+ end
13
+ return if new_attributes.blank?
14
+ attributes = new_attributes.stringify_keys
15
+ attributes.each do |k, v|
16
+ _assign_attribute(k, v)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def _assign_attribute(key, value)
23
+ public_send("#{key}=", value)
24
+ rescue NoMethodError
25
+ if respond_to?("#{key}=")
26
+ raise
27
+ end
28
+ end
29
+
30
+
31
+
32
+ end
33
+ end
@@ -1,6 +1,22 @@
1
1
  module GollumRails
2
2
  module Core
3
3
  extend ActiveSupport::Concern
4
+
5
+ ATTR_READERS = []
6
+ ATTR_WRITERS = [:name, :content, :format]
7
+ ATTR_ACCESSORS = [:commit, :gollum_page]
8
+
9
+ included do
10
+ ATTR_WRITERS.each do |a|
11
+ attr_writer a
12
+ end
13
+ ATTR_ACCESSORS.each do |a|
14
+ attr_accessor a
15
+ end
16
+
17
+ end
18
+
19
+
4
20
  module ClassMethods
5
21
 
6
22
  # Checks if the fileformat is supported
@@ -44,21 +60,6 @@ module GollumRails
44
60
  run_callbacks :initialize unless _initialize_callbacks.empty?
45
61
  end
46
62
 
47
- # Allows you to set all the attributes by passing in a hash of attributes with
48
- # keys matching the attribute name
49
- #
50
- # new_attributes - Hash - Hash of arguments
51
- def assign_attributes(new_attributes)
52
- if !new_attributes.respond_to?(:stringify_keys)
53
- raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."
54
- end
55
- return if new_attributes.blank?
56
- attributes = new_attributes.stringify_keys
57
- attributes.each do |k, v|
58
- _assign_attribute(k, v)
59
- end
60
- end
61
-
62
63
  def url_path #:nodoc:
63
64
  File.split(url)
64
65
  end
@@ -172,6 +173,27 @@ module GollumRails
172
173
 
173
174
  end
174
175
 
176
+ # Gets the pages format
177
+ def format
178
+ (@format || (@gollum_page.format||:markdown)).to_sym
179
+ end
180
+
181
+ def name
182
+ @name ||= (@gollum_page.name || "")
183
+ end
184
+
185
+ # == Outputs the pages filename on disc
186
+ #
187
+ # ext - Wether to output extension or not
188
+ def filename(ext=true)
189
+ @filename ||= (ext) ? @gollum_page.filename : @gollum_page.filename_stripped
190
+ end
191
+
192
+ def content
193
+ @content ||= (@gollum_page.content || "")
194
+ end
195
+
196
+
175
197
  private
176
198
 
177
199
  # == Gets the right commit out of 2 commits
@@ -185,14 +207,6 @@ module GollumRails
185
207
  return com
186
208
  end
187
209
 
188
- def _assign_attribute(key, value)
189
- public_send("#{key}=", value)
190
- rescue NoMethodError
191
- if respond_to?("#{key}=")
192
- raise
193
- end
194
- end
195
-
196
210
  # == Updates local attributes from gollum_page class
197
211
  #
198
212
  def _update_page_attributes
@@ -74,6 +74,7 @@ module GollumRails
74
74
  include ActiveModel::Validations
75
75
  end
76
76
  include Error
77
+ include Attributes
77
78
  include Core
78
79
  include Meta
79
80
  include Store
@@ -2,21 +2,6 @@ module GollumRails
2
2
  module Store
3
3
  extend ActiveSupport::Concern
4
4
 
5
-
6
- ATTR_READERS = []
7
- ATTR_WRITERS = [:name, :content, :format]
8
- ATTR_ACCESSORS = [:commit, :gollum_page]
9
-
10
- included do
11
- ATTR_WRITERS.each do |a|
12
- attr_writer a
13
- end
14
- ATTR_ACCESSORS.each do |a|
15
- attr_accessor a
16
- end
17
-
18
- end
19
-
20
5
  module ClassMethods
21
6
  # Gets the wiki instance
22
7
  def wiki
@@ -25,26 +10,6 @@ module GollumRails
25
10
  @wiki = Gollum::Wiki.new(Setup.wiki_path, Setup.wiki_options)
26
11
  end
27
12
  end
28
- # Gets the pages format
29
- def format
30
- (@format || (@gollum_page.format||:markdown)).to_sym
31
- end
32
-
33
- def name
34
- @name ||= (@gollum_page.name || "")
35
- end
36
-
37
- # == Outputs the pages filename on disc
38
- #
39
- # ext - Wether to output extension or not
40
- def filename(ext=true)
41
- @filename ||= (ext) ? @gollum_page.filename : @gollum_page.filename_stripped
42
- end
43
-
44
- def content
45
- @content ||= (@gollum_page.content || "")
46
- end
47
-
48
13
 
49
14
  private
50
15
  # == To static
@@ -0,0 +1,135 @@
1
+ module GollumRails
2
+ class Upload
3
+ if ActiveModel::VERSION::MAJOR == 4
4
+ include ActiveModel::Model
5
+ else
6
+ extend ActiveModel::Naming
7
+ extend ActiveModel::Callbacks
8
+ include ActiveModel::Conversion
9
+ include ActiveModel::Validations
10
+ end
11
+
12
+ autoload :ClassDefinitions, 'gollum_rails/upload/class_definitions'
13
+ autoload :FileTooBigError, 'gollum_rails/upload/file_too_big_error'
14
+
15
+ include Attributes
16
+ include Store
17
+ include ClassDefinitions
18
+
19
+ attr_accessor :file
20
+ attr_accessor :destination
21
+ attr_accessor :commit
22
+ attr_accessor :gollum_file
23
+
24
+ def initialize(attrs)
25
+ assign_attributes(attrs)
26
+ yield self if block_given?
27
+ end
28
+
29
+ def save!
30
+ if self.file
31
+ fullname = Gollum::Page.cname(self.file.original_filename)
32
+ tempfile = self.file
33
+ validate! tempfile
34
+ end
35
+
36
+ @dir = self.destination || self.class.destination
37
+ @fullname = fullname
38
+ ext = ::File.extname(fullname)
39
+
40
+ # Allowed formats in future
41
+ format = ext.split('.').last || "txt"
42
+ filename = ::File.basename(fullname, ext)
43
+ contents = ::File.read(tempfile)
44
+ #reponame = filename + '.' + format
45
+ head = self.class.wiki.repo.head
46
+
47
+ options = self.commit.merge(parent: head.commit)
48
+ committer = Gollum::Committer.new(self.class.wiki, options)
49
+ committer.add_to_index(@dir, filename, format, contents)
50
+ committer.after_commit do |cmntr, sha|
51
+ self.class.wiki.clear_cache
52
+ cmntr.update_working_dir(@dir, filename, format)
53
+ end
54
+ committer.commit
55
+ _update_gollum_file(File.join(@dir,@fullname))
56
+ self
57
+ end
58
+
59
+ def save
60
+ save!
61
+ rescue Gollum::DuplicatePageError
62
+ _update_gollum_file(File.join(@dir,@fullname))
63
+ self
64
+ rescue FileTooBigError => e
65
+ @error = e.message
66
+ self
67
+ end
68
+
69
+ def destroy(commit=nil)
70
+ return false if !persisted?
71
+ committer = Gollum::Committer.new(self.class.wiki, commit||self.commit)
72
+
73
+ committer.delete(self.gollum_file.path)
74
+
75
+ committer.after_commit do |index, sha|
76
+ path = self.gollum_file.path
77
+ dir = ::File.dirname(path)
78
+ dir = '' if dir == '.'
79
+ fullname = ::File.basename(path)
80
+ ext = ::File.extname(fullname)
81
+ format = ext.split('.').last || "txt"
82
+ filename = ::File.basename(fullname, ext)
83
+
84
+ self.class.wiki.clear_cache
85
+ index.update_working_dir(dir, filename, format)
86
+ end
87
+
88
+ sha = committer.commit
89
+ _update_gollum_file(nil)
90
+ sha
91
+ end
92
+
93
+ def self.create(attributes)
94
+ self.new(attributes).save
95
+ end
96
+
97
+ def self.find(path)
98
+ ins = self.new({})
99
+ ins._update_gollum_file(path)
100
+ ins
101
+ end
102
+
103
+ def persisted?
104
+ !!self.gollum_file
105
+ end
106
+
107
+ def validate!(tempfile)
108
+ if self.class.max_size
109
+ raise FileTooBigError,
110
+ "File is too big. Max. size is #{self.class.max_size}" if tempfile.size > self.class.max_size
111
+ end
112
+ end
113
+
114
+ def _find_gollum_file(path)
115
+ wiki.file(path)
116
+ end
117
+
118
+ def _update_gollum_file(path)
119
+ if path
120
+ self.gollum_file = _find_gollum_file(path)
121
+ else
122
+ self.gollum_file = nil
123
+ end
124
+ end
125
+
126
+ def to_s
127
+ if @error
128
+ "Error occured: <%s>" % @error
129
+ else
130
+ super
131
+ end
132
+ end
133
+
134
+ end
135
+ end
@@ -0,0 +1,25 @@
1
+
2
+ module GollumRails
3
+ class Upload
4
+ module ClassDefinitions
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ attr_accessor :destination
9
+ attr_accessor :overwrite
10
+ def max_filesize(size)
11
+ @max_size=size if size
12
+ end
13
+ def max_size
14
+ @max_size
15
+ end
16
+ def upload_directory(dir)
17
+ self.destination = dir
18
+ end
19
+ def overwrite_existing_files(bool)
20
+ self.overwrite = bool
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ module GollumRails
2
+ class Upload
3
+ class FileTooBigError < StandardError
4
+ end
5
+ end
6
+ end
data/spec/factories.rb CHANGED
@@ -1,8 +1,13 @@
1
+ require 'rack/test'
2
+ require 'rack/test/uploaded_file'
3
+
1
4
  FactoryGirl.define do
2
5
  trait :initialize do
3
6
  after(:build) do
7
+ g_path = File.expand_path('../utils/wiki.git', __FILE__)
8
+ `test -d #{g_path} || git init --bare #{g_path}`
4
9
  GollumRails::Setup.build do |config|
5
- GollumRails::Setup.repository = File.expand_path('../utils/wiki.git', __FILE__)
10
+ config.repository = File.expand_path('../utils/wiki.git', __FILE__)
6
11
  end
7
12
  end
8
13
  end
@@ -18,6 +23,19 @@ FactoryGirl.define do
18
23
  end
19
24
  initialize_with { attributes }
20
25
  end
26
+
27
+ factory :restrictions_upload, class: SampleClassDefinitions, traits: [:initialize] do
28
+ file Rack::Test::UploadedFile.new(File.expand_path('../GLD-LOTR-2T.jpg', __FILE__), "image/jpeg")
29
+ destination 'uploads'
30
+ initialize_with { new(attributes) }
31
+ commit { build(:commit_fakes) }
32
+ end
33
+ factory :upload, class: GollumRails::Upload, traits: [:initialize] do
34
+ file Rack::Test::UploadedFile.new(File.expand_path('../GLD-LOTR-2T.jpg', __FILE__), "image/jpeg")
35
+ destination 'uploads'
36
+ initialize_with { new(attributes) }
37
+ commit { build(:commit_fakes) }
38
+ end
21
39
  #factory :commit_fakes, class: DefaultCommit do
22
40
  #end
23
41
  factory :gollum_page_spec, traits: [:initialize, :markdown] do
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'active_support/core_ext/numeric'
3
+ require 'active_support/core_ext/module/attribute_accessors'
4
+
5
+ describe GollumRails::Upload::ClassDefinitions do
6
+
7
+
8
+ it "has a max filesize defined" do
9
+ expect(SampleClassDefinitions.max_size).to eq 2.bytes
10
+ end
11
+ it "has a upload directory defined" do
12
+ expect(SampleClassDefinitions.destination).to eq 'uploads'
13
+ end
14
+ it "overwrites existing files" do
15
+ expect(SampleClassDefinitions.overwrite) == true
16
+ end
17
+ describe "validation" do
18
+ let(:ins){build(:restrictions_upload)}
19
+ let(:ins2){build(:upload)}
20
+
21
+ it "fails if the file is bigger than 2byte" do
22
+ id2 = ins.save
23
+ id2 = ins.destroy
24
+ expect{ins.save!}.to raise_error GollumRails::Upload::FileTooBigError
25
+ end
26
+ end
27
+
28
+
29
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe GollumRails::Upload do
4
+ describe "#initialize(file, destination='uploads')" do
5
+ let(:ins){build(:upload)}
6
+ it "should set accessor file to file" do
7
+ expect(ins.file).to be_instance_of Rack::Test::UploadedFile
8
+ end
9
+ it "should set accessor destination to /uploads" do
10
+ expect(ins.destination) == "uploads"
11
+ end
12
+ it "should set accessor commit to factory hash" do
13
+ expect(ins.commit).to be_kind_of Hash
14
+ end
15
+ it "has not an empty commit" do
16
+ expect(ins.commit).not_to be_empty
17
+ end
18
+ end
19
+
20
+ describe "#save" do
21
+ let(:ins){build(:upload, destination: "blafasel")}
22
+
23
+ it "performs debugging" do
24
+ ins.save
25
+ file = GollumRails::Upload.wiki.file("blafasel/#{ins.file.original_filename}")
26
+ expect(file).not_to be_nil
27
+ ins.destroy
28
+ end
29
+ it "is persisted after save" do
30
+ ins.save
31
+ expect(ins.persisted?) == true
32
+ ins.destroy
33
+ end
34
+ it "is not persisted after destroy" do
35
+ ins.save
36
+ ins.destroy
37
+ expect(ins.persisted?) == false
38
+ end
39
+ it "is not persisted without saving" do
40
+ expect(ins.persisted?) == false
41
+ end
42
+ end
43
+
44
+ describe "#destroy" do
45
+ let(:ins){build(:upload, destination: "destroy")}
46
+ it "is empty after destruction" do
47
+ ins.destroy
48
+ file = GollumRails::Upload.find("destroy/#{ins.file.original_filename}")
49
+ expect(file.gollum_file).to be_nil
50
+ end
51
+ it "returns a commit id on destroy" do
52
+ ins.save
53
+ expect(ins.destroy).to be_instance_of(String)
54
+ end
55
+ end
56
+
57
+ describe "::create" do
58
+
59
+ end
60
+
61
+ describe "::find(path)" do
62
+
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ class SampleClassDefinitions < GollumRails::Upload
2
+ max_filesize 2
3
+ upload_directory 'uploads'
4
+ overwrite_existing_files true
5
+ end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.12
4
+ version: 1.5.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Kasper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -184,6 +184,7 @@ files:
184
184
  - lib/generators/gollum_rails/model/model_generator.rb
185
185
  - lib/generators/gollum_rails/model/templates/model_template.erb
186
186
  - lib/gollum_rails.rb
187
+ - lib/gollum_rails/attributes.rb
187
188
  - lib/gollum_rails/callbacks.rb
188
189
  - lib/gollum_rails/core.rb
189
190
  - lib/gollum_rails/error.rb
@@ -196,17 +197,24 @@ files:
196
197
  - lib/gollum_rails/setup/error.rb
197
198
  - lib/gollum_rails/setup/options.rb
198
199
  - lib/gollum_rails/store.rb
200
+ - lib/gollum_rails/upload.rb
201
+ - lib/gollum_rails/upload/class_definitions.rb
202
+ - lib/gollum_rails/upload/file_too_big_error.rb
199
203
  - lib/gollum_rails/validation.rb
200
204
  - spec/factories.rb
201
205
  - spec/gollum_rails/page_core_spec.rb
202
206
  - spec/gollum_rails/page_spec.rb
203
207
  - spec/gollum_rails/respository_spec.rb
204
208
  - spec/gollum_rails/setup_spec.rb
209
+ - spec/gollum_rails/upload/class_definitions_spec.rb
210
+ - spec/gollum_rails/upload_spec.rb
205
211
  - spec/gollum_rails/wiki_spec.rb
206
212
  - spec/spec_helper.rb
207
213
  - spec/support/default_commit.rb
208
214
  - spec/support/gollum_page_spec.rb
215
+ - spec/support/sample_upload.rb
209
216
  - spec/support/special_commit.rb
217
+ - uploads/GLD-LOTR-2T.jpg
210
218
  homepage: https://github.com/nirnanaaa/gollum_rails
211
219
  licenses:
212
220
  - AGPL