Class: Elasticsearch::Git::LiteBlob
- Inherits:
-
Object
- Object
- Elasticsearch::Git::LiteBlob
- Includes:
- Linguist::BlobHelper
- Defined in:
- lib/elasticsearch/git/repository.rb
Instance Attribute Summary collapse
-
#commit_id ⇒ Object
Returns the value of attribute commit_id.
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #encode!(message) ⇒ Object
-
#initialize(repo, raw_blob_hash) ⇒ LiteBlob
constructor
A new instance of LiteBlob.
Constructor Details
#initialize(repo, raw_blob_hash) ⇒ LiteBlob
Returns a new instance of LiteBlob.
426 427 428 429 430 431 |
# File 'lib/elasticsearch/git/repository.rb', line 426 def initialize(repo, raw_blob_hash) @id = raw_blob_hash[:oid] @path = raw_blob_hash[:path] @name = @path.split("/").last @data = encode!(repo.lookup(@id).content) end |
Instance Attribute Details
#commit_id ⇒ Object
Returns the value of attribute commit_id.
424 425 426 |
# File 'lib/elasticsearch/git/repository.rb', line 424 def commit_id @commit_id end |
#data ⇒ Object
Returns the value of attribute data.
424 425 426 |
# File 'lib/elasticsearch/git/repository.rb', line 424 def data @data end |
#id ⇒ Object
Returns the value of attribute id.
424 425 426 |
# File 'lib/elasticsearch/git/repository.rb', line 424 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
424 425 426 |
# File 'lib/elasticsearch/git/repository.rb', line 424 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
424 425 426 |
# File 'lib/elasticsearch/git/repository.rb', line 424 def path @path end |
Instance Method Details
#encode!(message) ⇒ Object
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/elasticsearch/git/repository.rb', line 433 def encode!() return nil unless .respond_to? :force_encoding # if message is utf-8 encoding, just return it .force_encoding("UTF-8") return if .valid_encoding? # return message if message type is binary detect = CharlockHolmes::EncodingDetector.detect() return .force_encoding("BINARY") if detect && detect[:type] == :binary # encoding message to detect encoding if detect && detect[:encoding] .force_encoding(detect[:encoding]) end # encode and clean the bad chars .replace clean() rescue encoding = detect ? detect[:encoding] : "unknown" "--broken encoding: #{encoding}" end |