Class: ResourceCrud

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

Instance Method Summary collapse

Constructor Details

#initialize(name, **props) ⇒ ResourceCrud

Returns a new instance of ResourceCrud.



4
5
6
7
8
# File 'lib/resource_crud.rb', line 4

def initialize(name, **props)
  @name = name
  @props = props
  @generator_hash = {}
end

Instance Method Details

#generatorObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/resource_crud.rb', line 10

def generator
  gem_path = Gem::Specification.find_by_name("ngcrud").gem_dir
  dirname = File.dirname("src/app/features/#{@name.downcase}")
  unless File.directory?(dirname)
    FileUtils::mkdir_p("src/app/features/#{@name.downcase}/#{@name.downcase}-create")
    FileUtils::mkdir_p("src/app/features/#{@name.downcase}/#{@name.downcase}-list")
  end

  p "Generating interface..."
  interface = ERB.new(File.open("#{gem_path}/lib/templates/resource_interface.erb").read)
  interface_file = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}.ts", "w")
  interface_file.write(interface.result(get_binding))
  interface_file.close
  p "Generating service..."
  service = ERB.new(File.open("#{gem_path}/lib/templates/resource_service.erb").read)
  service_file = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}.service.ts", "w")
  service_file.write(service.result(get_binding))
  service_file.close

  p "Generating components..."
  create_html = ERB.new(File.open("#{gem_path}/lib/templates/components/resource_create_html.erb").read)
  file_html = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}-create/#{@name.downcase}-create.component.html", "w")
  file_html.write(create_html.result(get_binding))
  file_html.close
  create_ts = ERB.new(File.open("#{gem_path}/lib/templates/components/resource_create_ts.erb").read)
  file_ts = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}-create/#{@name.downcase}-create.component.ts", "w")
  file_ts.write(create_ts.result(get_binding))
  file_ts.close

  list_html = ERB.new(File.open("#{gem_path}/lib/templates/components/resource_list_html.erb").read)
  file_html = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}-list/#{@name.downcase}-list.component.html", "w")
  file_html.write(list_html.result(get_binding))
  file_html.close
  list_ts = ERB.new(File.open("#{gem_path}/lib/templates/components/resource_list_ts.erb").read)
  file_ts = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}-list/#{@name.downcase}-list.component.ts", "w")
  file_ts.write(list_ts.result(get_binding))
  file_ts.close
  
end