Class: MyPath::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/mypath/handler.rb,
lib/mypath/handler/cwd.rb,
lib/mypath/handler/gem.rb

Direct Known Subclasses

CWD, Gem

Defined Under Namespace

Classes: CWD, Gem

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Handler

Returns a new instance of Handler.



26
27
28
# File 'lib/mypath/handler.rb', line 26

def initialize(path)
  self.path = self.class.clean_path(path)
end

Class Attribute Details

.listObject

Returns the value of attribute list.



5
6
7
# File 'lib/mypath/handler.rb', line 5

def list
  @list
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



24
25
26
# File 'lib/mypath/handler.rb', line 24

def path
  @path
end

Class Method Details

.clean_path(path) ⇒ Object



11
12
13
# File 'lib/mypath/handler.rb', line 11

def clean_path(path)
  path.gsub(/:.*/, "")
end

.for(path) ⇒ Object



15
16
17
18
19
20
# File 'lib/mypath/handler.rb', line 15

def for(path)
  handler = self.list.detect{|h| h.can_handle?(path)}
  if handler
    handler.new(path)
  end
end

.inherited(klass) ⇒ Object



7
8
9
# File 'lib/mypath/handler.rb', line 7

def inherited(klass)
  self.list |= [klass]
end