Class: ColiseumDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/culpa-coliseum/coliseum_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(to_eval, envelope, eval_args = nil) ⇒ ColiseumDSL

Returns a new instance of ColiseumDSL.



4
5
6
7
8
9
10
11
12
13
# File 'lib/culpa-coliseum/coliseum_dsl.rb', line 4

def initialize(to_eval, envelope, eval_args = nil)
  @dsl_attributes = {}
  @culpa_headers = {}
  @culpa_envelope = envelope
  if to_eval.is_a? String
    instance_eval File.read(to_eval), to_eval
  else
    instance_exec eval_args, &to_eval
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &blk) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/culpa-coliseum/coliseum_dsl.rb', line 58

def method_missing(sym, *args, &blk)
  @dsl_attributes[sym] = if ::Kernel.block_given?
                           ColiseumDSL.new(blk, @culpa_envelope).dsl_attributes
                         else
                           if args.count.zero?
                             nil
                           elsif args.count == 1
                             args[0]
                           else
                             args
                           end
                         end
end

Instance Attribute Details

#culpa_headersObject (readonly)

Returns the value of attribute culpa_headers.



2
3
4
# File 'lib/culpa-coliseum/coliseum_dsl.rb', line 2

def culpa_headers
  @culpa_headers
end

#culpa_statusObject (readonly)

Returns the value of attribute culpa_status.



2
3
4
# File 'lib/culpa-coliseum/coliseum_dsl.rb', line 2

def culpa_status
  @culpa_status
end

#dsl_attributesObject (readonly)

Returns the value of attribute dsl_attributes.



2
3
4
# File 'lib/culpa-coliseum/coliseum_dsl.rb', line 2

def dsl_attributes
  @dsl_attributes
end

Instance Method Details

#add_http_headers!(hdrs = {}) ⇒ Object



23
24
25
# File 'lib/culpa-coliseum/coliseum_dsl.rb', line 23

def add_http_headers!(hdrs = {})
  @culpa_headers.merge!(hdrs)
end

#array!(opts, &blk) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/culpa-coliseum/coliseum_dsl.rb', line 27

def array!(opts, &blk)
  if opts.is_a? Hash
    sym, items = opts.first
    @dsl_attributes[sym] = []
    items.each do |item|
      @dsl_attributes[sym] << ColiseumDSL.new(blk, @culpa_envelope, item).dsl_attributes
    end
  else
    @dsl_attributes = []
    opts.each do |item|
      @dsl_attributes << ColiseumDSL.new(blk, @culpa_envelope, item).dsl_attributes
    end
  end
end

#eObject



15
16
17
# File 'lib/culpa-coliseum/coliseum_dsl.rb', line 15

def e
  @culpa_envelope
end

#extract!(target, *attrs) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/culpa-coliseum/coliseum_dsl.rb', line 42

def extract!(target, *attrs)
  attrs.each do |att|
    @dsl_attributes[att] = if target.is_a? Hash
                             target[att] if target.key? att
                           else
                             begin
                               target.send(att)
                             rescue
                               # :nocov:
                               nil
                               # :nocov:
                             end
                           end
  end
end

#set_status_code!(code) ⇒ Object



19
20
21
# File 'lib/culpa-coliseum/coliseum_dsl.rb', line 19

def set_status_code!(code)
  @culpa_status = code
end