Class: Setting::TemplateSync

Inherits:
Setting
  • Object
show all
Defined in:
app/models/setting/template_sync.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.associate_typesObject



3
4
5
6
7
8
9
# File 'app/models/setting/template_sync.rb', line 3

def self.associate_types
  {
    'always' => _('Always'),
    'new' => _('New'),
    'never' => _('Never')
  }
end

.load_defaultsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/setting/template_sync.rb', line 19

def self.load_defaults
  return unless super

  %w(template_sync_filter template_sync_branch).each { |s| Setting::BLANK_ATTRS << s }

  self.transaction do
    [
      self.set('template_sync_verbose', N_('Choose verbosity for Rake task importing templates'), false, N_('Verbosity')),
      self.set('template_sync_associate', N_('Associate templates to OS'), 'new', N_('Associate'), nil, { :collection => Proc.new { self.associate_types } }),
      self.set('template_sync_prefix', N_('The string all imported templates should begin with'), "Community ", N_('Prefix')),
      self.set('template_sync_dirname', N_('The directory within the Git repo containing the templates'), '/', N_('Dirname')),
      self.set('template_sync_filter', N_('Import or export names matching this regex (case-insensitive; snippets are not filtered)'), nil, N_('Filter')),
      self.set('template_sync_repo', N_('Default Git repo to sync from'), 'https://github.com/theforeman/community-templates.git', N_('Repo')),
      self.set('template_sync_negate', N_('Negate the prefix (for purging) / filter (for importing/exporting)'), false, N_('Negate')),
      self.set('template_sync_branch', N_('Default branch in Git repo'), nil, N_('Branch')),
      self.set('template_sync_metadata_export_mode', N_('Default metadata export mode, refresh re-renders metadata, keep will keep existing metadata, remove exports template withou metadata'), 'refresh', N_('Metadata export mode'), nil, { :collection => Proc.new { self. } }),
      self.set('template_sync_force', N_('Should importing overwrite locked templates?'), false, N_('Force import')),
    ].compact.each { |s| self.create! s.update(:category => "Setting::TemplateSync") }
  end

  true
end

.metadata_export_mode_typesObject



11
12
13
14
15
16
17
# File 'app/models/setting/template_sync.rb', line 11

def self.
  {
    'refresh' => _('Refresh'),
    'keep' => _('Keep'),
    'remove' => _('Remove')
  }
end

Instance Method Details

#validate_template_sync_associate(record) ⇒ Object



42
43
44
45
46
47
# File 'app/models/setting/template_sync.rb', line 42

def validate_template_sync_associate(record)
  values = record.class.associate_types.keys
  if record.value && !values.include?(record.value)
    record.errors[:base] << (_("template_sync_associate must be one of %s") % values.join(', '))
  end
end

#validate_template_sync_metadata_export_mode(record) ⇒ Object



49
50
51
52
53
54
# File 'app/models/setting/template_sync.rb', line 49

def (record)
  values = record.class..keys
  if record.value && !values.include?(record.value)
    record.errors[:base] << (_("template_sync_metadata_export_mode must be one of %s") % values.join(', '))
  end
end