Class: RailsEdgeTest::Dsl::Edge

Inherits:
Struct
  • Object
show all
Defined in:
lib/rails_edge_test/dsl/edge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Edge

Returns a new instance of Edge.



8
9
10
11
# File 'lib/rails_edge_test/dsl/edge.rb', line 8

def initialize(*args)
  super
  @let_cache = {}
end

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



6
7
8
# File 'lib/rails_edge_test/dsl/edge.rb', line 6

def action
  @action
end

#controller_classObject

Returns the value of attribute controller_class

Returns:

  • (Object)

    the current value of controller_class



6
7
8
# File 'lib/rails_edge_test/dsl/edge.rb', line 6

def controller_class
  @controller_class
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



6
7
8
# File 'lib/rails_edge_test/dsl/edge.rb', line 6

def description
  @description
end

Instance Method Details

#controllerObject



19
20
21
# File 'lib/rails_edge_test/dsl/edge.rb', line 19

def controller
  @controller ||= controller_class.new
end

#perform_get(parameters = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/rails_edge_test/dsl/edge.rb', line 27

def perform_get(parameters = {})
  request.assign_parameters(
    ::Rails.application.routes,
    controller_class.controller_path,
    action.to_s,
    parameters
  )

  @response = controller.dispatch(action, request)
end

#produce_elm_file(module_name, ivar: nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rails_edge_test/dsl/edge.rb', line 38

def produce_elm_file(module_name, ivar: nil)
  json = produce_json(ivar: ivar)
  json = json.gsub("\\", "\\\\\\\\") # unbelievably, this replaces \ with \\

  filepath = File.join(
    RailsEdgeTest.configuration.elm_path,
    'Edge',
    controller_class.name.gsub('::','/')
  )

  full_module_name =
    "#{controller_class.name.gsub('::','.')}.#{module_name}"

  data = "    module Edge.\#{full_module_name} exposing (json)\n\n\n    json : String\n    json =\n        \"\"\"\n    \#{json}\n        \"\"\"\n  ELM\n\n  write_file(filepath, module_name+'.elm', data)\nend\n"

#requestObject



15
16
17
# File 'lib/rails_edge_test/dsl/edge.rb', line 15

def request
  @request ||= ActionController::TestRequest.new
end

#responseObject



23
24
25
# File 'lib/rails_edge_test/dsl/edge.rb', line 23

def response
  @response
end