class SocialSnippet::Resolvers::BaseResolver
Attributes
core[R]
visited[R]
Public Class Methods
new(new_core)
click to toggle source
Constructor
@param new_core [::SocialSnippet::Core]
# File lib/social_snippet/resolvers/base_resolver.rb, line 11 def initialize(new_core) @core = new_core @visited = Set.new end
Public Instance Methods
each_child_snippet(snippet, context, base_tag) { |t, tag_info, child_snippet, new_context| ... }
click to toggle source
Call block each snip tags
@param snippet [Snippet] @param context [Context] The context of current code @param base_tag [Tag]
# File lib/social_snippet/resolvers/base_resolver.rb, line 21 def each_child_snippet(snippet, context, base_tag) raise "must be passed snippet" unless snippet.is_a?(Snippet) snippet.snip_tags.each do |tag_info| t = tag_info[:tag].set_by_tag(base_tag) new_context = context.clone if new_context.root_text? new_context.set_path "" move_context_by_tag! new_context, t else move_context_by_tag! new_context, t overwrite_tag_in_same_repository! new_context, t update_tag_path_by_context! new_context, t end resolve_tag_repo_ref! t child_snippet = core.repo_manager.get_snippet(new_context, t) t.set_path new_context.path if block_given? yield t, tag_info[:line_no], child_snippet, new_context end end end
Private Instance Methods
is_self(tag, context)
click to toggle source
# File lib/social_snippet/resolvers/base_resolver.rb, line 104 def is_self(tag, context) tag.repo === context.repo && tag.path === context.path end
is_visited(tag)
click to toggle source
# File lib/social_snippet/resolvers/base_resolver.rb, line 100 def is_visited(tag) visited.include? tag.to_path end
move_context_by_tag!(context, tag)
click to toggle source
# File lib/social_snippet/resolvers/base_resolver.rb, line 49 def move_context_by_tag!(context, tag) if tag.has_repo? if tag.has_ref? context.move tag.path, tag.repo, tag.ref else context.move tag.path, tag.repo end else context.move tag.path end end
overwrite_tag_in_same_repository!(context, tag)
click to toggle source
Overwrite tag
# File lib/social_snippet/resolvers/base_resolver.rb, line 62 def overwrite_tag_in_same_repository!(context, tag) if context.is_in_repository? && tag.has_repo? === false tag.set_repo context.repo tag.set_ref context.ref end end
resolve_tag_repo_ref!(tag)
click to toggle source
Resolve tag’s ref
# File lib/social_snippet/resolvers/base_resolver.rb, line 77 def resolve_tag_repo_ref!(tag) return unless tag.has_repo? repo = core.repo_manager.find_repository(tag.repo) # set latest version if tag.has_ref? === false if repo.has_package_versions? tag.set_ref repo.latest_package_version else tag.set_ref repo.current_ref end else unless repo.has_ref?(tag.ref) new_ref = repo.latest_version(tag.ref) raise "error" if new_ref.nil? tag.set_ref new_ref end end end
update_tag_path_by_context!(context, tag)
click to toggle source
Update tag path by context
# File lib/social_snippet/resolvers/base_resolver.rb, line 70 def update_tag_path_by_context!(context, tag) if tag.has_repo? tag.set_path context.path end end
visit(tag)
click to toggle source
# File lib/social_snippet/resolvers/base_resolver.rb, line 96 def visit(tag) visited.add tag.to_path end