Module: RailsAssist::Artifact::CRUD::Update

Defined in:
lib/rails_artifactor/base/crud/update.rb

Instance Method Summary collapse

Instance Method Details

#insert_into_artifact(name, options = {}, &block) ⇒ Object Also known as: update_artifact



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails_artifactor/base/crud/update.rb', line 5

def insert_into_artifact name, options={}, &block
  type = get_type(options)
  file = existing_file_name(name, type)

  raise "No file could be determined: #{file} from name: #{name} of type: #{type}" if !file
  raise "File to insert in not found: #{file} for #{type}" if !File.file?(file)

  marker = marker_option(name, options)

  blip = send :"#{type}_marker", name, options
  options1 = options.merge marker

  before_last = options[:before_last]

  res = File.insert_into file, options1, &block
  if !res
    # try with :embedded option if default doesn't work
    mrk_opt = marker_option name, options.merge(:model_type => :embedded)
    options.merge! mrk_opt

    File.insert_into file, options, &block
  end
end

#remove_from_artifact(name, options = {}, &block) ⇒ Object



30
31
32
33
34
# File 'lib/rails_artifactor/base/crud/update.rb', line 30

def remove_from_artifact name, options={}, &block
  type = options[:type]
  file = existing_file_name(name, type)
  File.remove_content_from file, options, &block
end

#remove_from_artifacts(*names, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/rails_artifactor/base/crud/update.rb', line 36

def remove_from_artifacts *names, &block
  options = last_option(names)
  type = options[:type]
  artifacts = names.flatten.select_labels

  artifacts.each do |name|
    file = existing_file_name(name, type)
    File.remove_content_from file, options, &block
  end
end

#replace_in_artifact(name, options = {}, &block) ⇒ Object



48
49
50
51
52
# File 'lib/rails_artifactor/base/crud/update.rb', line 48

def replace_in_artifact name, options={}, &block
  type = options[:type]
  file = existing_file_name(name, type)
  File.replace_content_from file, options, &block
end

#replace_in_artifacts(*names, &block) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/rails_artifactor/base/crud/update.rb', line 54

def replace_in_artifacts *names, &block
  options = last_option(names)
  type = options[:type]
  artifacts = names.flatten.select_labels

  artifacts.each do |name|
    file = existing_file_name(name, type)
    File.replace_content_from file, options, &block
  end
end