Module: Pakada::Module
- Defined in:
- lib/pakada/module.rb
Class Attribute Summary collapse
-
.descendants ⇒ Object
readonly
Returns the value of attribute descendants.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.descendants ⇒ Object (readonly)
Returns the value of attribute descendants.
8 9 10 |
# File 'lib/pakada/module.rb', line 8 def descendants @descendants end |
Class Method Details
.detect_name(klass) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/pakada/module.rb', line 39 def detect_name(klass) name = klass.gsub(/^Pakada::/, ""). gsub(/([A-Z]+)([A-Z][a-z])/, "\\1_\\2"). gsub(/([a-z])([A-Z])/, "\\1_\\2"). gsub(/::/, "_"). downcase return name.to_sym if name.match /^[a-z0-9_]+$/ end |
.detect_path(file) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pakada/module.rb', line 48 def detect_path(file) file = String(file) filepath = nil filepath = file if file =~ /^\// && File.exists?(file) $LOAD_PATH.each do |dir| x = File.join dir, file if File.exists? x filepath = File. x break end end unless filepath return unless filepath segments = File.dirname(filepath).split("/").reverse pos = segments.find_index("lib") || -1 path = segments[(pos + 1)..-1].reverse.join("/") Pathname.new File.(path) end |
.included(klass) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pakada/module.rb', line 10 def included(klass) klass.send :include, Hooked class << klass attr_reader :pakada_name, :path, :dependencies end unless klass.pakada_name klass.instance_variable_set :@pakada_name, detect_name(klass.to_s) end unless klass.pakada_name raise "Could not detect name for module #{klass}" end unless klass.path # use Kernel.caller instead of self.caller so Mocha doesn't explode... file = Kernel.caller[0].split(":")[0] klass.instance_variable_set :@path, detect_path(file) else klass.instance_variable_set :@path, Pathname.new(klass.path) end unless klass.dependencies klass.instance_variable_set :@dependencies, [] end @descendants << klass end |
Instance Method Details
#boot ⇒ Object
82 |
# File 'lib/pakada/module.rb', line 82 def boot; end |
#dependencies ⇒ Object
78 79 80 |
# File 'lib/pakada/module.rb', line 78 def dependencies self.class.dependencies end |
#hooks ⇒ Object
84 |
# File 'lib/pakada/module.rb', line 84 def hooks; end |
#pakada_name ⇒ Object
70 71 72 |
# File 'lib/pakada/module.rb', line 70 def pakada_name self.class.pakada_name end |
#path ⇒ Object
74 75 76 |
# File 'lib/pakada/module.rb', line 74 def path self.class.path end |