Class: Kangaru::Paths

Inherits:
Object
  • Object
show all
Defined in:
lib/kangaru/paths.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:) ⇒ Paths

Returns a new instance of Paths.



15
16
17
# File 'lib/kangaru/paths.rb', line 15

def initialize(source:)
  @source = Pathname.new(source)
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



13
14
15
# File 'lib/kangaru/paths.rb', line 13

def source
  @source
end

Instance Method Details

#collapsed_dirsObject



50
51
52
# File 'lib/kangaru/paths.rb', line 50

def collapsed_dirs
  [models_dir, controllers_dir].map(&:to_s)
end

#dirObject

The directory that contains the gem.



20
21
22
# File 'lib/kangaru/paths.rb', line 20

def dir
  @dir ||= gem_path.dirname
end

#gem_path(*fragments, ext: nil) ⇒ Object

Paths inside the root directory of the gem.



30
31
32
# File 'lib/kangaru/paths.rb', line 30

def gem_path(*fragments, ext: nil)
  build_path(*fragments, dir: gem_dir, ext:)
end

#lib_path(*fragments, ext: :rb) ⇒ Object

Paths inside the lib path of the gem. Conventionally contains two files:

  1. gem_name.rb (source_file)

  2. gem_name/*.rb (app_path)



37
38
39
# File 'lib/kangaru/paths.rb', line 37

def lib_path(*fragments, ext: :rb)
  build_path(*fragments, dir: lib_dir, ext:)
end

#nameObject

Infers the gem name from the source filename.



25
26
27
# File 'lib/kangaru/paths.rb', line 25

def name
  @name ||= source.basename(".rb").to_s
end

#path(*fragments, ext: :rb) ⇒ Object

The gem application directory (gem/lib/gem_name).



42
43
44
# File 'lib/kangaru/paths.rb', line 42

def path(*fragments, ext: :rb)
  build_path(*fragments, dir: app_dir, ext:)
end

#view_path(*fragments, ext: :erb) ⇒ Object



46
47
48
# File 'lib/kangaru/paths.rb', line 46

def view_path(*fragments, ext: :erb)
  build_path(*fragments, dir: views_dir, ext:)
end