Merge pull request #4949 from jekyll/fix-drop-rubocop-errors

Merge pull request 4949
This commit is contained in:
jekyllbot 2016-05-25 16:24:29 -07:00
commit a15958d5a7
3 changed files with 14 additions and 8 deletions

View File

@ -5,9 +5,9 @@ module Jekyll
class DocumentDrop < Drop class DocumentDrop < Drop
extend Forwardable extend Forwardable
NESTED_OBJECT_FIELD_BLACKLIST = %w{ NESTED_OBJECT_FIELD_BLACKLIST = %w(
content output excerpt next previous content output excerpt next previous
}.freeze ).freeze
mutable false mutable false
@ -40,6 +40,8 @@ module Jekyll
# Generate a Hash for use in generating JSON. # Generate a Hash for use in generating JSON.
# This is useful if fields need to be cleared before the JSON can generate. # This is useful if fields need to be cleared before the JSON can generate.
# #
# state - the JSON::State object which determines the state of current processing.
#
# Returns a Hash ready for JSON generation. # Returns a Hash ready for JSON generation.
def hash_for_json(state = nil) def hash_for_json(state = nil)
to_h.tap do |hash| to_h.tap do |hash|

View File

@ -88,7 +88,9 @@ module Jekyll
# Returns an Array of strings which represent method-specific keys. # Returns an Array of strings which represent method-specific keys.
def content_methods def content_methods
@content_methods ||= ( @content_methods ||= (
self.class.instance_methods - Jekyll::Drops::Drop.instance_methods - NON_CONTENT_METHODS self.class.instance_methods \
- Jekyll::Drops::Drop.instance_methods \
- NON_CONTENT_METHODS
).map(&:to_s).reject do |method| ).map(&:to_s).reject do |method|
method.end_with?("=") method.end_with?("=")
end end
@ -144,15 +146,17 @@ module Jekyll
# This is useful if fields need to be cleared before the JSON can generate. # This is useful if fields need to be cleared before the JSON can generate.
# #
# Returns a Hash ready for JSON generation. # Returns a Hash ready for JSON generation.
def hash_for_json(state = nil) def hash_for_json(*)
to_h to_h
end end
# Generate a JSON representation of the Drop. # Generate a JSON representation of the Drop.
# #
# state - the JSON::State object which determines the state of current processing.
#
# Returns a JSON representation of the Drop in a String. # Returns a JSON representation of the Drop in a String.
def to_json(state = nil) def to_json(state = nil)
require 'json' require "json"
JSON.generate(hash_for_json(state), state) JSON.generate(hash_for_json(state), state)
end end
@ -165,7 +169,7 @@ module Jekyll
keys.each(&block) keys.each(&block)
end end
def each(&block) def each
each_key.each do |key| each_key.each do |key|
yield key, self[key] yield key, self[key]
end end

View File

@ -19,13 +19,13 @@ module Jekyll
def to_h def to_h
@to_h ||= { @to_h ||= {
"version" => version, "version" => version,
"environment" => environment "environment" => environment
} }
end end
def to_json(state = nil) def to_json(state = nil)
require 'json' require "json"
JSON.generate(to_h, state) JSON.generate(to_h, state)
end end
end end