Module: AutoGenerator::ClassMethods

Defined in:
backend/app/model/mixins/auto_generator.rb

Instance Method Summary collapse

Instance Method Details

#auto_generate(opts) ⇒ Object



47
48
49
50
# File 'backend/app/model/mixins/auto_generator.rb', line 47

def auto_generate(opts)
  properties_to_auto_generate.delete_if {|generate_opts| generate_opts[:property] == opts[:property] }
  properties_to_auto_generate.push(opts)
end

#create_from_json(json, opts = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'backend/app/model/mixins/auto_generator.rb', line 29

def create_from_json(json, opts = {})
  modified = false

  properties_to_auto_generate.each do |generate_opts|
    if (generate_opts[:only_if] and generate_opts[:only_if].call(json)) or json[generate_opts[:property]].nil?
      json[generate_opts[:property]] = generate_opts[:generator].call(json)
      modified = true
    end
  end

  obj = super

  obj.mark_as_system_modified if modified

  obj
end

#properties_to_auto_generateObject



53
54
55
56
57
# File 'backend/app/model/mixins/auto_generator.rb', line 53

def properties_to_auto_generate
  @properties_to_auto_generate ||= []

  @properties_to_auto_generate
end