Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/git/git-scm.com.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/doc_version.rb')
-rw-r--r--app/models/doc_version.rb47
1 files changed, 24 insertions, 23 deletions
diff --git a/app/models/doc_version.rb b/app/models/doc_version.rb
index 1b27aafe..5338ac28 100644
--- a/app/models/doc_version.rb
+++ b/app/models/doc_version.rb
@@ -11,9 +11,13 @@ class DocVersion < ApplicationRecord
belongs_to :doc_file
scope :with_includes, -> { includes(:doc) }
- scope :for_version, ->(version) { where(language: "en").joins(:version).where(versions: {name: version}).limit(1).first }
- scope :latest_version, ->(lang = "en") { where(language: lang).joins(:version).order("versions.vorder DESC").limit(1).first }
- scope :version_changes, -> { where(language: "en").with_includes.joins(:version).order("versions.vorder DESC") }
+ scope :for_version, lambda { |version|
+ where(language: "en").joins(:version).where(versions: { name: version }).limit(1).first
+ }
+ scope :latest_version, lambda { |lang = "en"|
+ where(language: lang).joins(:version).order("versions.vorder DESC").limit(1).first
+ }
+ scope :version_changes, -> { where(language: "en").with_includes.joins(:version).order("versions.vorder DESC") }
delegate :name, to: :version
delegate :committed, to: :version
@@ -23,26 +27,24 @@ class DocVersion < ApplicationRecord
# 1: subtractions
# 2: 8 - (add + sub)
def diff(doc_version)
- begin
- diff_out = Diffy::Diff.new(self.doc.plain, doc_version.doc.plain)
- first_chars=diff_out.to_s.gsub(/(.)[^\n]*\n/, '\1')
- adds = first_chars.count("+")
- mins = first_chars.count("-")
- total = mins + adds
- if total > 8
- min = (8.0 / total)
- adds = (adds * min).round
- mins = (mins * min).round
- total = 8
- end
- [adds, mins, 8 - total]
- rescue
- [0, 0, 8]
+ diff_out = Diffy::Diff.new(doc.plain, doc_version.doc.plain)
+ first_chars = diff_out.to_s.gsub(/(.)[^\n]*\n/, '\1')
+ adds = first_chars.count("+")
+ mins = first_chars.count("-")
+ total = mins + adds
+ if total > 8
+ min = (8.0 / total)
+ adds = (adds * min).round
+ mins = (mins * min).round
+ total = 8
end
+ [adds, mins, 8 - total]
+ rescue StandardError
+ [0, 0, 8]
end
def index
- file = self.doc_file
+ file = doc_file
doc = self.doc
client = ElasticClient.instance
@@ -51,13 +53,12 @@ class DocVersion < ApplicationRecord
type: "man_doc",
id: file.name,
body: {
- name: file.name,
- blob_sha: doc.blob_sha,
- text: doc.plain
+ name: file.name,
+ blob_sha: doc.blob_sha,
+ text: doc.plain
}
rescue StandardError
nil
end
end
-
end