Module: FlightConfig::Updater::ClassMethods

Includes:
Reader::ClassMethods
Defined in:
lib/flight_config/updater.rb

Instance Method Summary collapse

Methods included from Reader::ClassMethods

#new!, #read, #read_or_new

Methods included from Core::ClassMethods

#_path, #allow_missing_read, #data_core

Instance Method Details

#create(*a, &b) ⇒ Object



80
81
82
83
84
85
# File 'lib/flight_config/updater.rb', line 80

def create(*a, &b)
  new!(*a) do |config|
    Updater.create_error_if_exists(config)
    Updater.create_or_update(config, action: 'create', &b)
  end
end

#create_or_update(*a, &b) ⇒ Object



73
74
75
76
77
78
# File 'lib/flight_config/updater.rb', line 73

def create_or_update(*a, &b)
  mode = File.exists?(_path(*a))
  new!(*a, read_mode: mode) do |config|
    Updater.create_or_update(config, action: 'create_or_update', &b)
  end.tap { |c| c.generate_indices if c.respond_to?(:generate_indices) }
end

#update(*a, &b) ⇒ Object



66
67
68
69
70
71
# File 'lib/flight_config/updater.rb', line 66

def update(*a, &b)
  new!(*a, read_mode: true) do |config|
    Updater.update_error_if_missing(config)
    Updater.create_or_update(config, action: 'update', &b)
  end
end