Sha256: 6c94eb07aba9d411a6d10309eea926d11dcca676a6e67f6007b614c645c9f54d

Contents?: true

Size: 1.31 KB

Versions: 14

Compression:

Stored size: 1.31 KB

Contents

# -*- encoding : utf-8 -*-

class Card
  class Content
    module Chunk
      class Reference < Abstract
        attr_writer :referee_name
        attr_accessor :name

        def referee_name
          return if name.nil?

          @referee_name ||= referee_raw_name
          @referee_name = @referee_name.absolute_name card.name
        rescue Card::Error::NotFound
          # do not break on missing id/codename references.
        end

        def referee_raw_name
          Name[render_obj(name)]
        end

        def referee_card
          @referee_card ||= referee_name && Card.fetch(referee_name)
        end

        private

        def replace_name_reference old_name, new_name
          @referee_card = @referee_name = nil
          replacing_content_object name, old_name, new_name do
            @name = name.to_name.swap old_name, new_name
          end
        end

        def replacing_content_object obj, old_name, new_name
          if obj.is_a? Content
            obj.find_chunks(:Reference).each do |chunk|
              chunk.swap_name old_name, new_name
            end
          elsif obj.present?
            yield
          end
        end

        def render_obj raw
          return raw unless format && raw.is_a?(Content)

          format.process_content raw
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
card-mod-content-0.18.1 lib/card/content/chunk/reference.rb
card-mod-content-0.18.0 lib/card/content/chunk/reference.rb
card-mod-content-0.17.0 lib/card/content/chunk/reference.rb
card-mod-content-0.16.0 lib/card/content/chunk/reference.rb
card-mod-content-0.15.5 lib/card/content/chunk/reference.rb
card-mod-content-0.15.4 lib/card/content/chunk/reference.rb
card-mod-content-0.15.3 lib/card/content/chunk/reference.rb
card-mod-content-0.15.2.pre1 lib/card/content/chunk/reference.rb
card-mod-content-0.15.1.1 lib/card/content/chunk/reference.rb
card-mod-content-0.15.1 lib/card/content/chunk/reference.rb
card-mod-content-0.15.0 lib/card/content/chunk/reference.rb
card-mod-content-0.14.2 lib/card/content/chunk/reference.rb
card-mod-content-0.14.1 lib/card/content/chunk/reference.rb
card-mod-content-0.14.0 lib/card/content/chunk/reference.rb