Class: OpenRosa::FieldContext

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

Overview

Helper class for evaluating blocks in group/repeat DSL This allows for clean nested field definitions within groups and repeats

Instance Method Summary collapse

Constructor Details

#initialize(fields_array) ⇒ FieldContext

Returns a new instance of FieldContext.



7
8
9
# File 'lib/open_rosa/field_context.rb', line 7

def initialize(fields_array)
  @fields = fields_array
end

Instance Method Details

#boolean(name, options = {}) ⇒ Object



23
24
25
# File 'lib/open_rosa/field_context.rb', line 23

def boolean(name, options = {})
  @fields << Fields::Boolean.new(name, options)
end

#group(name, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/open_rosa/field_context.rb', line 39

def group(name, options = {}, &)
  nested_fields = []
  if block_given?
    context = FieldContext.new(nested_fields)
    context.instance_eval(&)
  end

  @fields << Fields::Group.new(name, options.merge(fields: nested_fields))
end

#input(name, options = {}) ⇒ Object



11
12
13
# File 'lib/open_rosa/field_context.rb', line 11

def input(name, options = {})
  @fields << Fields::Input.new(name, options)
end

#range(name, options = {}) ⇒ Object



31
32
33
# File 'lib/open_rosa/field_context.rb', line 31

def range(name, options = {})
  @fields << Fields::Range.new(name, options)
end

#repeat(name, options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/open_rosa/field_context.rb', line 49

def repeat(name, options = {}, &)
  nested_fields = []
  if block_given?
    context = FieldContext.new(nested_fields)
    context.instance_eval(&)
  end

  @fields << Fields::Repeat.new(name, options.merge(fields: nested_fields))
end

#select(name, options = {}) ⇒ Object



19
20
21
# File 'lib/open_rosa/field_context.rb', line 19

def select(name, options = {})
  @fields << Fields::Select.new(name, options)
end

#select1(name, options = {}) ⇒ Object



15
16
17
# File 'lib/open_rosa/field_context.rb', line 15

def select1(name, options = {})
  @fields << Fields::Select1.new(name, options)
end

#trigger(name, options = {}) ⇒ Object



35
36
37
# File 'lib/open_rosa/field_context.rb', line 35

def trigger(name, options = {})
  @fields << Fields::Trigger.new(name, options)
end

#upload(name, options = {}) ⇒ Object



27
28
29
# File 'lib/open_rosa/field_context.rb', line 27

def upload(name, options = {})
  @fields << Fields::Upload.new(name, options)
end