Class: Kangaru::Paths
- Inherits:
-
Object
- Object
- Kangaru::Paths
- Defined in:
- lib/kangaru/paths.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #collapsed_dirs ⇒ Object
-
#dir ⇒ Object
The directory that contains the gem.
-
#gem_path(*fragments, ext: nil) ⇒ Object
Paths inside the root directory of the gem.
-
#initialize(source:) ⇒ Paths
constructor
A new instance of Paths.
-
#lib_path(*fragments, ext: :rb) ⇒ Object
Paths inside the lib path of the gem.
-
#name ⇒ Object
Infers the gem name from the source filename.
-
#path(*fragments, ext: :rb) ⇒ Object
The gem application directory (gem/lib/gem_name).
- #view_path(*fragments, ext: :erb) ⇒ Object
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
#source ⇒ Object (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_dirs ⇒ Object
50 51 52 |
# File 'lib/kangaru/paths.rb', line 50 def collapsed_dirs [models_dir, controllers_dir].map(&:to_s) end |
#dir ⇒ Object
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:
-
gem_name.rb (source_file)
-
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 |
#name ⇒ Object
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 |