Module: ActiveSupportDecorators

Defined in:
lib/active_support_decorators/version.rb,
lib/active_support_decorators/active_support_decorators.rb

Constant Summary collapse

VERSION =
'2.0.2'

Class Method Summary collapse

Class Method Details

.all(file_name, const_path = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/active_support_decorators/active_support_decorators.rb', line 35

def self.all(file_name, const_path = nil)
  file = sanitize(file_name)

  if const_path
    file = const_path.underscore
  else
    first_autoload_match = all_autoload_paths.find { |p| file.include?(p) }
    file.sub!(first_autoload_match, '') if first_autoload_match
  end

  relative_target = "#{file}#{pattern}.rb"

  expanded_paths.map { |path| File.join(path, relative_target) }.select { |candidate| File.file?(candidate) }
end

.debugObject



19
20
21
# File 'lib/active_support_decorators/active_support_decorators.rb', line 19

def self.debug
  @debug ||= false
end

.debug=(debugging_enabled) ⇒ Object



23
24
25
# File 'lib/active_support_decorators/active_support_decorators.rb', line 23

def self.debug=(debugging_enabled)
  @debug = debugging_enabled
end

.expanded_pathsObject



15
16
17
# File 'lib/active_support_decorators/active_support_decorators.rb', line 15

def self.expanded_paths
  paths.map { |p| Dir[p] }.flatten
end

.is_decorator?(file_name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/active_support_decorators/active_support_decorators.rb', line 31

def self.is_decorator?(file_name)
  sanitize(file_name).ends_with?(pattern)
end

.log(message) ⇒ Object



27
28
29
# File 'lib/active_support_decorators/active_support_decorators.rb', line 27

def self.log(message)
  puts message if debug
end

.original_const_name(file_name) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/active_support_decorators/active_support_decorators.rb', line 50

def self.original_const_name(file_name)
  first_match = expanded_paths.find { |path| file_name.include?(path) }

  if first_match
    sanitize(file_name).sub("#{first_match}/", '').sub(pattern, '').camelize
  else
    nil
  end
end

.pathsObject



3
4
5
# File 'lib/active_support_decorators/active_support_decorators.rb', line 3

def self.paths
  @paths ||= []
end

.patternObject



7
8
9
# File 'lib/active_support_decorators/active_support_decorators.rb', line 7

def self.pattern
  @pattern ||= '_decorator'
end

.pattern=(pattern) ⇒ Object



11
12
13
# File 'lib/active_support_decorators/active_support_decorators.rb', line 11

def self.pattern=(pattern)
  @pattern = pattern
end