mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-28 03:01:03 -04:00
Initialize mutations for Drops only if necessary (#7657)
Merge pull request 7657
This commit is contained in:
@@ -30,7 +30,6 @@ module Jekyll
|
||||
# Returns nothing
|
||||
def initialize(obj)
|
||||
@obj = obj
|
||||
@mutations = {} # only if mutable: true
|
||||
end
|
||||
|
||||
# Access a method in the Drop or a field in the underlying hash data.
|
||||
@@ -42,8 +41,8 @@ module Jekyll
|
||||
#
|
||||
# Returns the value for the given key, or nil if none exists
|
||||
def [](key)
|
||||
if self.class.mutable? && @mutations.key?(key)
|
||||
@mutations[key]
|
||||
if self.class.mutable? && mutations.key?(key)
|
||||
mutations[key]
|
||||
elsif self.class.invokable? key
|
||||
public_send key
|
||||
else
|
||||
@@ -70,7 +69,7 @@ module Jekyll
|
||||
public_send("#{key}=", val)
|
||||
elsif respond_to?(key.to_s)
|
||||
if self.class.mutable?
|
||||
@mutations[key] = val
|
||||
mutations[key] = val
|
||||
else
|
||||
raise Errors::DropMutationException, "Key #{key} cannot be set in the drop."
|
||||
end
|
||||
@@ -100,7 +99,7 @@ module Jekyll
|
||||
# Returns true if the given key is present
|
||||
def key?(key)
|
||||
return false if key.nil?
|
||||
return true if self.class.mutable? && @mutations.key?(key)
|
||||
return true if self.class.mutable? && mutations.key?(key)
|
||||
|
||||
respond_to?(key) || fallback_data.key?(key)
|
||||
end
|
||||
@@ -113,7 +112,7 @@ module Jekyll
|
||||
# Returns an Array of unique keys for content for the Drop.
|
||||
def keys
|
||||
(content_methods |
|
||||
@mutations.keys |
|
||||
mutations.keys |
|
||||
fallback_data.keys).flatten
|
||||
end
|
||||
|
||||
@@ -204,6 +203,12 @@ module Jekyll
|
||||
return yield(key) unless block.nil?
|
||||
return default unless default.nil?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mutations
|
||||
@mutations ||= {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user