Class: Cleon::Home

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#homeObject (readonly)

Returns the value of attribute home.



5
6
7
# File 'lib/cleon/home.rb', line 5

def home
  @home
end

Instance Method Details

#baseString

Returns base name of the gem.

Returns:

  • (String)

    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_dirObject



74
75
76
# File 'lib/cleon/home.rb', line 74

def base_dir
  @bdir ||= File.join(lib, base)
end

#bundleObject

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

#constObject



86
87
88
# File 'lib/cleon/home.rb', line 86

def const
  @const ||= base.split(?_).map(&:capitalize).join
end

#dirsObject



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

Returns:

  • (Boolean)


12
13
14
# File 'lib/cleon/home.rb', line 12

def exist?
  Dir.exist?(home)
end

#gemspecString

Returns filename of .gemspec.

Returns:

  • (String)

    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

Returns:

  • (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_homeObject



25
26
27
# File 'lib/cleon/home.rb', line 25

def inside_home
  inside_home? ? yield : Dir.chdir(@home) { yield }
end

#inside_home?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/cleon/home.rb', line 21

def inside_home?
  @home == File.basename(Dir.pwd)
end

#libObject



70
71
72
# File 'lib/cleon/home.rb', line 70

def lib
  @lib ||= File.join(home, 'lib')
end

#sourceObject



82
83
84
# File 'lib/cleon/home.rb', line 82

def source
  @source ||= "#{base}.rb"
end

#test_dirObject



78
79
80
# File 'lib/cleon/home.rb', line 78

def test_dir
  @tdir ||= File.join(home, 'test')
end