Class: ActionDSL

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

Instance Method Summary collapse

Constructor Details

#initialize(controller, name:, &block) ⇒ ActionDSL

Returns a new instance of ActionDSL.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cerulean.rb', line 4

def initialize(controller, name:, &block)
  @controller = controller
  @name = name
  @meta = {}

  instance_eval(&block)

  # yuck
  meta = @controller.class_variable_get(:@@meta)
  meta[name] = @meta
  @controller.class_variable_set(:@@meta, meta)
end

Instance Method Details

#form(key = nil, klass) ⇒ Object



30
31
32
# File 'lib/cerulean.rb', line 30

def form(key=nil, klass)
  @meta[:form] = { key: key, klass: klass }
end

#param(name, type = String, opts = {}) ⇒ Object



21
22
23
24
# File 'lib/cerulean.rb', line 21

def param(name, type=String, opts={})
  @meta[:params] ||= {}
  @meta[:params][name] = opts.merge({ type: type })
end

#params(&block) ⇒ Object



17
18
19
# File 'lib/cerulean.rb', line 17

def params(&block)
  instance_eval(&block)
end

#presenter(presenter) ⇒ Object



26
27
28
# File 'lib/cerulean.rb', line 26

def presenter(presenter)
  @meta[:presenter] = presenter
end

#request(&block) ⇒ Object



34
35
36
# File 'lib/cerulean.rb', line 34

def request(&block)
  @controller.send(:define_method, @name, &block)
end