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.



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

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.



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

def action_name
  @action_name
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



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

def model_name
  @model_name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

#top_level_js_namespaceObject

Returns the value of attribute top_level_js_namespace.



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

def top_level_js_namespace
  @top_level_js_namespace
end

Instance Method Details

#runObject



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

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

  JsForView.new(self).create_file
  AppJs.new(self).append_script
  ViewFile.new(self).append_script
end