Class: Microframe::Generator

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/microframe/application/generators/generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



7
8
9
# File 'lib/microframe/application/generators/generator.rb', line 7

def app_name
  @app_name
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/microframe/application/generators/generator.rb', line 7

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/microframe/application/generators/generator.rb', line 7

def type
  @type
end

#xtrasObject (readonly)

Returns the value of attribute xtras.



7
8
9
# File 'lib/microframe/application/generators/generator.rb', line 7

def xtras
  @xtras
end

Class Method Details

.source_rootObject



9
10
11
# File 'lib/microframe/application/generators/generator.rb', line 9

def self.source_root
  File.join(__dir__, "samples")
end

Instance Method Details

#g(type, name, *xtras) ⇒ Object



37
38
39
# File 'lib/microframe/application/generators/generator.rb', line 37

def g(type, name, *xtras)
  invoke :generate, [type, name, *xtras]
end

#generate(type, name, *xtras) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/microframe/application/generators/generator.rb', line 21

def generate(type, name, *xtras)
  @type = type.downcase
  @name = name.downcase
  @xtras ||= xtras

  if type == "controller"
    template("sample_controller.tt", File.join(target_root, "controllers", "#{name}_controller.rb"))
    create_views
  elsif type == "model"
    template("sample_model.tt", File.join(target_root, "models", "#{name}.rb"))
  elsif type == "view"
    create_views
  end
end

#new(name) ⇒ Object



14
15
16
17
18
# File 'lib/microframe/application/generators/generator.rb', line 14

def new(name)
  @app_name = name
  directory("app_sample", "#{app_name}")
  init_with_shell_cmds
end