Class: RubyJard::PathClassifier
- Inherits:
-
Object
- Object
- RubyJard::PathClassifier
- Defined in:
- lib/ruby_jard/path_classifier.rb
Overview
Classify a particular path by its orign such as stdlib, gem, evaluation, etc. Usage
type, *info = PathClassifier.new.class('lib/abc')
Constant Summary collapse
- GEM_PATTERN =
/(.*)-(\d+\.\d+[.\d]*[.\d]*[-.\w]*)/i.freeze
- STDLIB_PATTERN =
/(.*)\.rb$/.freeze
- INTERNAL_PATTERN =
/<internal:[^>]+>/.freeze
- EVALUATION_SIGNATURE =
'(eval)'
- RUBY_SCRIPT_SIGNATURE =
'-e'
- TYPES =
[ TYPE_SOURCE_TREE = :source_tree, TYPE_GEM = :gem, TYPE_STDLIB = :stdlib, TYPE_INTERNAL = :internal, TYPE_EVALUATION = :evaluation, TYPE_RUBY_SCRIPT = :ruby_script, TYPE_UNKNOWN = :unknown ].freeze
Instance Method Summary collapse
- #classify(path) ⇒ Object
-
#initialize ⇒ PathClassifier
constructor
A new instance of PathClassifier.
Constructor Details
#initialize ⇒ PathClassifier
Returns a new instance of PathClassifier.
28 29 30 |
# File 'lib/ruby_jard/path_classifier.rb', line 28 def initialize @gem_paths = fetch_gem_paths end |
Instance Method Details
#classify(path) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby_jard/path_classifier.rb', line 32 def classify(path) return TYPE_UNKNOWN if path.nil? return TYPE_INTERNAL if try_classify_internal(path) return TYPE_EVALUATION if try_classify_evaluation(path) return TYPE_RUBY_SCRIPT if try_classify_ruby_script(path) return TYPE_SOURCE_TREE if try_classify_source_tree(path) matched, *info = try_classify_gem(path) return TYPE_GEM, *info if matched matched, *info = try_classify_stdlib(path) return TYPE_STDLIB, *info if matched TYPE_UNKNOWN end |