Module: Rapid::Web::ControllerHelpers

Defined in:
lib/rapid/web/controller_helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



6
7
8
# File 'lib/rapid/web/controller_helpers.rb', line 6

def self.registered(app)
  app.helpers self
end

Instance Method Details

#application_pathObject



10
11
12
# File 'lib/rapid/web/controller_helpers.rb', line 10

def application_path
  ENV["APP"]
end

#gem_pathObject



22
23
24
# File 'lib/rapid/web/controller_helpers.rb', line 22

def gem_path
  self.class.gem_path
end

#public_pathObject



14
15
16
# File 'lib/rapid/web/controller_helpers.rb', line 14

def public_path
  File.join gem_path, 'public', 'rapid', rapid_name if gem_path && rapid_name
end

#rapid_nameObject



18
19
20
# File 'lib/rapid/web/controller_helpers.rb', line 18

def rapid_name
  self.class.rapid_name
end

#setting_params(options = {}) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/rapid/web/controller_helpers.rb', line 26

def setting_params options = {}
  param_name = options[:param] || :settings
  param = params[param_name]
  return if param.nil?
  
  setting_params_recurse param
end

#setting_params_recurse(source, destination = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rapid/web/controller_helpers.rb', line 34

def setting_params_recurse source, destination = {}
  source.each do |key, value|
    if value.is_a? Hash
      is_on = value.delete "on"
      
      if is_on == "0"
        destination[key] = false
      elsif is_on == "1" && value.empty?
        destination[key] = true
      else
        destination[key] = setting_params_recurse(value)
      end
      
    elsif value.blank?
      destination[key] = nil
    else
      destination[key] = value
    end
  end
  
  destination
end