Class: RailsEdgeTest::Dsl::Action

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Action

Returns a new instance of Action.



3
4
5
6
7
# File 'lib/rails_edge_test/dsl/action.rb', line 3

def initialize(*args)
  super
  @edges = {}
  @let_handler = LetHandler.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object

support calling methods defined in controller



35
36
37
38
39
40
41
# File 'lib/rails_edge_test/dsl/action.rb', line 35

def method_missing(method_name, *arguments, &block)
  if controller.respond_to?(method_name)
    controller.public_send(method_name, *arguments, &block)
  else
    super
  end
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller

Returns:

  • (Object)

    the current value of controller



2
3
4
# File 'lib/rails_edge_test/dsl/action.rb', line 2

def controller
  @controller
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/rails_edge_test/dsl/action.rb', line 2

def name
  @name
end

Instance Method Details

#__edgesObject



22
23
24
# File 'lib/rails_edge_test/dsl/action.rb', line 22

def __edges
  @edges
end

#__let_handlerObject



26
27
28
# File 'lib/rails_edge_test/dsl/action.rb', line 26

def __let_handler
  @let_handler
end

#controller_classObject



30
31
32
# File 'lib/rails_edge_test/dsl/action.rb', line 30

def controller_class
  controller.controller_class
end

#edge(description, &block) ⇒ Object



9
10
11
12
# File 'lib/rails_edge_test/dsl/action.rb', line 9

def edge(description, &block)
  edge = Edge.new(description, self)
  @edges[edge] = block
end

#generate(title, &block) ⇒ Object



18
19
20
# File 'lib/rails_edge_test/dsl/action.rb', line 18

def generate(title, &block)
  @let_handler.add_definition("generate_#{title}", &block)
end

#let(title, &block) ⇒ Object



14
15
16
# File 'lib/rails_edge_test/dsl/action.rb', line 14

def let(title, &block)
  @let_handler.add_definition(title, &block)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

always define respond_to_missing? when defining method_missing: thoughtbot.com/blog/always-define-respond-to-missing-when-overriding

Returns:

  • (Boolean)


45
46
47
# File 'lib/rails_edge_test/dsl/action.rb', line 45

def respond_to_missing?(method_name, include_private = false)
  controller.respond_to?(method_name) || super
end