Module: Templatable

Included in:
FileWriter
Defined in:
lib/ez_gen/templatable.rb

Instance Method Summary collapse

Instance Method Details

#class_template(class_name) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/ez_gen/templatable.rb', line 34

def class_template(class_name)
  <<~HEREDOC
    class #{class_name}

    end
  HEREDOC
end

#generator_templateObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ez_gen/templatable.rb', line 59

def generator_template
  <<~'HEREDOC'
    lower_name = ARGV.first
    upper_name = lower_name.split("_").map{|word| word.capitalize}.join

    class_file = File.open("lib/#{lower_name}.rb", "w")
    class_file.write("class #{upper_name}\n\nend")
    class_file.close

    test_file = File.open("test/#{lower_name}_test.rb", "w")
    test_file.write(
    "require \'./test/test_helper.rb\'
    require \'./lib/#{lower_name}.rb\'

    class #{upper_name}Test < Minitest::Test
      def setup
        @#{lower_name} = #{upper_name}.new
      end

      def test_it_exists
        assert_instance_of #{upper_name}, @#{lower_name}
      end
    end"
    )
    test_file.close
    eval File.read(test_file)
    puts ""
    puts "Created \'lib/#{lower_name}.rb\' and \'test/#{lower_name}_test.rb\'"
    puts ""
    HEREDOC
end

#pr_templateObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ez_gen/templatable.rb', line 120

def pr_template
  <<~HEREDOC
    ## Description

    ## Type of change
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [ ] Refactor (non-breaking change which maintains existing functionality)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    ## Notes

    ## Test Results
    ```

    ```
  HEREDOC

end

#rake_templateObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ez_gen/templatable.rb', line 2

def rake_template
  <<~HEREDOC
    require "rake/testtask"

    Rake::TestTask.new do |task|
      task.pattern = "test/*_test.rb"
    end

    desc "Run single test file based on class name, ex: rake test_class person"
    task :test_class do
      ARGV.each { |arg| task arg.to_sym do ; end }
      eval File.read("./test/\#{ARGV.last}_test.rb")
    end

    desc "Generate new class and test, ex: rake g person"
    task :g do
      ARGV.each { |arg| task arg.to_sym do ; end }
      ruby "./.scripts/generate.rb \#{ARGV.last}"
    end
  HEREDOC
end

#readme_templateObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ez_gen/templatable.rb', line 91

def readme_template
  <<~HEREDOC
    # Title

    *Description*

    ## Table of Contents:
    - [Running Locally](#running-locally)
    - [Tech Stack](#tech-stack)
    - [Contributors](#contributors)

    ***
    ## Running Locally
    [top](#table-of-contents)
    * Instructions to run locally

    ***
    ## Tech Stack
    [top](#table-of-contents)
    * Language version
    * Framework, gems, etc.

    ***
    ## Contributors
    [top](#table-of-contents)
    * [<NAME HERE>](<LINK TO GITHUB>)
  HEREDOC
end

#test_helper_templateObject



24
25
26
27
28
29
30
31
32
# File 'lib/ez_gen/templatable.rb', line 24

def test_helper_template
  <<~HEREDOC
    require 'simplecov'
    SimpleCov.start
    require 'minitest/autorun'
    require 'minitest/pride'
    require 'mocha/minitest'
  HEREDOC
end

#test_template(lower_name, upper_name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ez_gen/templatable.rb', line 42

def test_template(lower_name, upper_name)
  <<~HEREDOC
    require './test/test_helper.rb'
    require './lib/#{lower_name}.rb'

    class #{upper_name}Test < Minitest::Test
      def setup
        @#{lower_name} = #{upper_name}.new
      end

      def test_it_exists
        assert_instance_of #{upper_name}, @#{lower_name}
      end
    end
  HEREDOC
end