Class: StrokeDB::Document::MetaModulesCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/strokedb/document.rb

Instance Method Summary collapse

Constructor Details

#initialize(store, subject) ⇒ MetaModulesCollector

Returns a new instance of MetaModulesCollector.



680
681
682
683
# File 'lib/strokedb/document.rb', line 680

def initialize(store, subject)
  @store   = store
  @subject = subject
end

Instance Method Details

#at_top_level?(mod) ⇒ Boolean

Returns:

  • (Boolean)


697
698
699
# File 'lib/strokedb/document.rb', line 697

def at_top_level?(mod)
  mod == Module || mod.nil?
end

#collect!Object



701
702
703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/strokedb/document.rb', line 701

def collect!
  meta_names = []

  case @subject
  when VERSIONREF, DOCREF
    meta_names << resolve_module_name($1)
  when Array
    meta_names = @subject.map { |subj| subj = MetaModulesCollector.new(@store, subj).collect! }.flatten
  when Document
    meta_names << @subject[:name]
  end

  meta_names
end

#has_defined_constant_for_meta?(mod, metadoc) ⇒ Boolean

Returns:

  • (Boolean)


724
725
726
# File 'lib/strokedb/document.rb', line 724

def has_defined_constant_for_meta?(mod, metadoc)
  top_level_meta?(mod, metadoc) || has_meta_definition?(mod, metadoc)
end

#has_meta_definition?(mod, metadoc) ⇒ Boolean

Returns:

  • (Boolean)


732
733
734
# File 'lib/strokedb/document.rb', line 732

def has_meta_definition?(mod, metadoc)
  (mod && mod.constants.include?(metadoc[:name]))
end

#lookup_version_for_meta(meta) ⇒ Object



716
717
718
719
720
721
722
# File 'lib/strokedb/document.rb', line 716

def lookup_version_for_meta(meta)
  version = case meta
            when VERSIONREF then $2
            else nil
            end
  version
end

#resolve_module_name(uuid) ⇒ Object



685
686
687
688
689
690
691
692
693
694
695
# File 'lib/strokedb/document.rb', line 685

def resolve_module_name(uuid)
  if metadoc = @store.find(uuid, self.lookup_version_for_meta(@subject))
    mod = Module.find_by_nsurl(metadoc[:nsurl])

    if self.has_defined_constant_for_meta?(mod, metadoc)
      at_top_level?(mod) ? "::#{metadoc[:name]}" : "#{mod.name}::#{metadoc[:name]}"
    else
      Meta.resolve_uuid_name(metadoc[:nsurl], metadoc[:name])
    end
  end
end

#top_level_meta?(mod, doc) ⇒ Boolean

Returns:

  • (Boolean)


728
729
730
# File 'lib/strokedb/document.rb', line 728

def top_level_meta?(mod, doc)
  (mod == Module && Object.constants.include?(doc[:name]))
end