Class: ForemanTemplates::Action

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_templates/action.rb

Direct Known Subclasses

TemplateExporter, TemplateImporter

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Action

Returns a new instance of Action.



35
36
37
38
39
# File 'app/services/foreman_templates/action.rb', line 35

def initialize(args = {})
  @taxonomies = { :organizations => args[:organization_params] || {},
                  :locations => args[:location_params] || {} }
  assign_attributes args
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'app/services/foreman_templates/action.rb', line 23

def method_missing(method, *args, &block)
  if self.class.setting_overrides.include?(method)
    instance_variable_get("@#{method}")
  else
    super
  end
end

Class Method Details

.file_repo_start_withObject



11
12
13
# File 'app/services/foreman_templates/action.rb', line 11

def self.file_repo_start_with
  ['/']
end

.git_repo_start_withObject



7
8
9
# File 'app/services/foreman_templates/action.rb', line 7

def self.git_repo_start_with
  %w{http:// https:// git:// ssh:// git+ssh:// ssh+git://}
end

.repo_start_withObject



15
16
17
# File 'app/services/foreman_templates/action.rb', line 15

def self.repo_start_with
  git_repo_start_with + file_repo_start_with
end

.setting_overridesObject



19
20
21
# File 'app/services/foreman_templates/action.rb', line 19

def self.setting_overrides
  %i(verbose prefix dirname filter repo negate branch http_proxy_policy)
end

Instance Method Details

#get_absolute_repo_pathObject



45
46
47
# File 'app/services/foreman_templates/action.rb', line 45

def get_absolute_repo_path
  File.expand_path(@repo)
end

#git_repo?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/services/foreman_templates/action.rb', line 41

def git_repo?
  @repo.start_with?(*self.class.git_repo_start_with)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/services/foreman_templates/action.rb', line 31

def respond_to_missing?(method, include_private = false)
  self.class.setting_overrides.include?(method)
end

#verify_path!(path) ⇒ Object



49
50
51
52
53
# File 'app/services/foreman_templates/action.rb', line 49

def verify_path!(path)
  msg = _("Using file-based synchronization, but couldn't access %s. ") % path
  msg += _("Please check the access permissions/SELinux and make sure it is readable/writable for the web application user account, typically '%s'.") % 'foreman'
  raise PathAccessException, msg unless Dir.exist?(path)
end