lib/wcc/contentful/link_visitor.rb in wcc-contentful-1.2.0 vs lib/wcc/contentful/link_visitor.rb in wcc-contentful-1.2.1
- old
+ new
@@ -2,13 +2,11 @@
# The LinkVisitor is a utility class for walking trees of linked entries.
# It is used internally by the Store layer to compose the resulting resolved hashes.
# But you can use it too!
class WCC::Contentful::LinkVisitor
- attr_reader :entry
- attr_reader :fields
- attr_reader :depth
+ attr_reader :entry, :fields, :depth
# @param [Hash] entry The entry hash (resolved or unresolved) to walk
# @param [Array<Symbol>] The type of fields to select from the entry tree.
# Must be one of `:Link`, `:Entry`, `:Asset`.
# @param [Fixnum] depth (optional) How far to walk down the tree of links. Be careful of
@@ -64,10 +62,10 @@
end
end
def each_field(field)
each_locale(field) do |val, locale|
- if val&.is_a?(Array)
+ if val.is_a?(Array)
val.each_with_index do |v, index|
yield(v, field, locale, index) unless v.nil?
end
else
yield(val, field, locale) unless val.nil?