Class: JsGenerator::SetupJs

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace: nil, model_name:, action_name:) ⇒ SetupJs

Returns a new instance of SetupJs.



16
17
18
19
20
21
# File 'lib/js_generator.rb', line 16

def initialize(namespace: nil, model_name:, action_name:)
  @namespace = namespace
  @model_name = model_name
  @action_name = action_name
  @top_level_js_namespace = ENV['TOP_LEVEL_JS_NAMESPACE']
end

Instance Attribute Details

#action_nameObject (readonly)

Returns the value of attribute action_name.



13
14
15
# File 'lib/js_generator.rb', line 13

def action_name
  @action_name
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



13
14
15
# File 'lib/js_generator.rb', line 13

def model_name
  @model_name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



13
14
15
# File 'lib/js_generator.rb', line 13

def namespace
  @namespace
end

#top_level_js_namespaceObject

Returns the value of attribute top_level_js_namespace.



14
15
16
# File 'lib/js_generator.rb', line 14

def top_level_js_namespace
  @top_level_js_namespace
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/js_generator.rb', line 23

def run
  if top_level_js_namespace.nil?
    raise Error.new('Please set TOP_LEVEL_JS_NAMESPACE in .env')
  end

  create_file
  append_script
  append_script_tag

  puts "✨ All done!"
end