class Locomotive::Wagon::PullBaseCommand

Public Class Methods

pull(api_client, current_site, path, env) click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 9
def self.pull(api_client, current_site, path, env)
  new(api_client, current_site, path, env).pull
end

Public Instance Methods

_pull_with_timezone() click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 21
def _pull_with_timezone
  Time.use_zone(current_site.try(:timezone)) do
    _pull
  end
end
clean_attributes(attributes) click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 44
def clean_attributes(attributes)
  # remove nil or empty values
  attributes.delete_if { |_, v| v.nil? || v == '' || (v.is_a?(Hash) && v.empty?) }
end
default_locale() click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 80
def default_locale
  current_site.locales.first
end
dump(element, options = {}) click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 32
def dump(element, options = {})
  if element.is_a?(Hash)
    StyledYAML.dump(element.dup.tap do |attributes|
      [*options[:inline]].each do |name|
        attributes[name] = StyledYAML.inline(attributes[name])
      end
    end)
  else
    element.to_yaml
  end.gsub(/\A---\n/, '')
end
instrument(action = nil, payload = {}, &block) click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 27
def instrument(action = nil, payload = {}, &block)
  name = [instrument_base_name, [*action]].flatten.compact.join('.')
  ActiveSupport::Notifications.instrument(name, { name: resource_name }.merge(payload), &block)
end
instrument_base_name() click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 72
def instrument_base_name
  'wagon.pull'
end
is_default_locale?(locale) click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 84
def is_default_locale?(locale)
  default_locale == locale
end
locales() click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 88
def locales
  current_site.locales
end
pull() click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 13
def pull
  instrument do
    instrument :start
    self._pull_with_timezone
    instrument :done
  end
end
reset_file(filepath) click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 67
def reset_file(filepath)
  _filepath = File.join(path, filepath)
  FileUtils.rm(_filepath) if File.exists?(_filepath)
end
resource_name() click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 76
def resource_name
  self.class.name[/::Pull(\w+)Command$/, 1].underscore
end
write_to_file(filepath, content = nil, mode = 'w+') { || ... } click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.rb, line 49
def write_to_file(filepath, content = nil, mode = 'w+', &block)
  _filepath = File.join(path, filepath)

  folder = File.dirname(_filepath)

  FileUtils.mkdir_p(folder) unless File.exists?(folder)

  File.open(_filepath, mode) do |file|
    if content
      file.write(content)
    elsif block_given?
      file.write(yield)
    else
      file.write('')
    end
  end
end