Module: Rails3::Assist::Artifact::CRUD::Update

Defined in:
lib/rails3_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
# File 'lib/rails3_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 
  
  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



28
29
30
31
32
# File 'lib/rails3_artifactor/base/crud/update.rb', line 28

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



34
35
36
37
38
39
40
41
42
43
# File 'lib/rails3_artifactor/base/crud/update.rb', line 34

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



46
47
48
49
50
# File 'lib/rails3_artifactor/base/crud/update.rb', line 46

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



52
53
54
55
56
57
58
59
60
61
# File 'lib/rails3_artifactor/base/crud/update.rb', line 52

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