Class: Cleon::Home
- Inherits:
-
Object
- Object
- Cleon::Home
- Defined in:
- lib/cleon/home.rb
Overview
The cleon home folder information
Constant Summary collapse
- BUNDLE_OPTIONS =
end
"--no-exe --no-coc --no-ext --no-mit --test=minitest"
Instance Attribute Summary collapse
-
#home ⇒ Object
readonly
Returns the value of attribute home.
Instance Method Summary collapse
-
#base ⇒ String
Base name of the gem.
- #base_dir ⇒ Object
-
#bundle ⇒ Object
Creates Cleon's gem structure.
- #const ⇒ Object
- #dirs ⇒ Object
- #exist? ⇒ Boolean
-
#gemspec ⇒ String
Filename of .gemspec.
- #home? ⇒ Boolean
-
#initialize(home = Dir.pwd) ⇒ Home
constructor
when cloning cleon, the user is outside the home when cloning thing, the user is inside the home.
- #inside_home ⇒ Object
- #inside_home? ⇒ Boolean
- #lib ⇒ Object
- #source ⇒ Object
- #test_dir ⇒ Object
Constructor Details
#initialize(home = Dir.pwd) ⇒ Home
when cloning cleon, the user is outside the home when cloning thing, the user is inside the home
8 9 10 |
# File 'lib/cleon/home.rb', line 8 def initialize(home = Dir.pwd) @home = File.basename(home).downcase end |
Instance Attribute Details
#home ⇒ Object (readonly)
Returns the value of attribute home.
5 6 7 |
# File 'lib/cleon/home.rb', line 5 def home @home end |
Instance Method Details
#base ⇒ String
Returns base name of the gem.
66 67 68 |
# File 'lib/cleon/home.rb', line 66 def base @base ||= File.basename(gemspec, '.gemspec').split('-').first.downcase end |
#base_dir ⇒ Object
74 75 76 |
# File 'lib/cleon/home.rb', line 74 def base_dir @bdir ||= File.join(lib, base) end |
#bundle ⇒ Object
Creates Cleon's gem structure
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cleon/home.rb', line 31 def bundle system "bundle gem #{@home} #{BUNDLE_OPTIONS}" log = [] inside_home do dirs .select{|dir| !Dir.exist?(dir)} .each{|dir| Dir.mkdir(dir); log << dir} # patch_gemspec end end |
#const ⇒ Object
86 87 88 |
# File 'lib/cleon/home.rb', line 86 def const @const ||= base.split(?_).map(&:capitalize).join end |
#dirs ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/cleon/home.rb', line 90 def dirs [ "lib/#{base}", "lib/#{base}/basics", "lib/#{base}/services", "lib/#{base}/entities", "test/#{base}", "test/#{base}/services", "test/#{base}/entities" ] end |
#exist? ⇒ Boolean
12 13 14 |
# File 'lib/cleon/home.rb', line 12 def exist? Dir.exist?(home) end |
#gemspec ⇒ String
Returns filename of .gemspec.
101 102 103 104 105 106 107 108 |
# File 'lib/cleon/home.rb', line 101 def gemspec @gemspec ||= begin # hack for test generators inside fresh gem with TODO tmp = inside_home { Dir.glob('*.gemspec').first } tmp = File.basename(Dir.pwd) unless tmp tmp end end |
#home? ⇒ Boolean
16 17 18 19 |
# File 'lib/cleon/home.rb', line 16 def home? return false unless gemspec dirs.all?{|dir| Dir.exist?(dir)} end |
#inside_home ⇒ Object
25 26 27 |
# File 'lib/cleon/home.rb', line 25 def inside_home inside_home? ? yield : Dir.chdir(@home) { yield } end |
#inside_home? ⇒ Boolean
21 22 23 |
# File 'lib/cleon/home.rb', line 21 def inside_home? @home == File.basename(Dir.pwd) end |
#lib ⇒ Object
70 71 72 |
# File 'lib/cleon/home.rb', line 70 def lib @lib ||= File.join(home, 'lib') end |
#source ⇒ Object
82 83 84 |
# File 'lib/cleon/home.rb', line 82 def source @source ||= "#{base}.rb" end |
#test_dir ⇒ Object
78 79 80 |
# File 'lib/cleon/home.rb', line 78 def test_dir @tdir ||= File.join(home, 'test') end |