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
- .all(file_name, const_path = nil) ⇒ Object
- .debug ⇒ Object
- .debug=(debugging_enabled) ⇒ Object
- .expanded_paths ⇒ Object
- .is_decorator?(file_name) ⇒ Boolean
- .log(message) ⇒ Object
- .original_const_name(file_name) ⇒ Object
- .paths ⇒ Object
- .pattern ⇒ Object
- .pattern=(pattern) ⇒ Object
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" .map { |path| File.join(path, relative_target) }.select { |candidate| File.file?(candidate) } end |
.debug ⇒ Object
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_paths ⇒ Object
15 16 17 |
# File 'lib/active_support_decorators/active_support_decorators.rb', line 15 def self. paths.map { |p| Dir[p] }.flatten end |
.is_decorator?(file_name) ⇒ 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() puts 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 = .find { |path| file_name.include?(path) } if first_match sanitize(file_name).sub("#{first_match}/", '').sub(pattern, '').camelize else nil end end |
.paths ⇒ Object
3 4 5 |
# File 'lib/active_support_decorators/active_support_decorators.rb', line 3 def self.paths @paths ||= [] end |
.pattern ⇒ Object
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 |