Module: CastGroupable

Extended by:
ActiveSupport::Concern
Included in:
Intervention, InterventionGroupParameter
Defined in:
app/models/concerns/cast_groupable.rb

Instance Method Summary collapse

Instance Method Details

#add_group_parameter!(*args) {|group| ... } ⇒ Object

Add cast group

Yields:

  • (group)

33
34
35
36
37
38
39
40
# File 'app/models/concerns/cast_groupable.rb', line 33

def add_group_parameter!(*args)
  raise 'No procedure' unless procedure
  attributes = args.extract_options!
  name = args.shift
  attributes[:reference_name] = name
  group = group_parameters.create!(attributes)
  yield group if block_given?
end

#add_parameter!(parameter_name, *args, &block) ⇒ Object Also known as: add!

Adds a cast or a cast_group to current cast_groupable


5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/models/concerns/cast_groupable.rb', line 5

def add_parameter!(parameter_name, *args, &block)
  raise 'No procedure' unless procedure
  attributes = args.extract_options!
  parameter = procedure.find!(parameter_name)
  if parameter.is_a?(Procedo::Procedure::ProductParameter)
    add_product_parameter!(parameter_name, args.shift, attributes)
  elsif parameter.is_a?(Procedo::Procedure::GroupParameter)
    add_group_parameter!(parameter_name, attributes, &block)
  else
    raise "Cannot add unknown parameter: #{parameter_name.inspect}"
  end
end

#add_product_parameter!(*args) ⇒ Object

Add cast


21
22
23
24
25
26
27
28
29
30
# File 'app/models/concerns/cast_groupable.rb', line 21

def add_product_parameter!(*args)
  raise 'No procedure' unless procedure
  attributes = args.extract_options!
  name = args.shift
  product = args.shift
  parameter = procedure.find!(name)
  attributes[:reference_name] = name
  attributes[:product] ||= product
  send(parameter.reflection_name).create!(attributes)
end