Module: ParametersExtra

Defined in:
lib/parameters_extra.rb,
lib/parameters_extra/args.rb,
lib/parameters_extra/version.rb,
lib/parameters_extra/processor.rb,
lib/parameters_extra/method_registry.rb

Defined Under Namespace

Classes: Args, MethodRegistry, Processor

Constant Summary collapse

ClassMethodRegistry =
Hash.new{|h, k| h[k] = MethodRegistry.new}
FileRegistry =
Set.new
VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.class_key(cls) ⇒ Object



42
43
44
45
46
# File 'lib/parameters_extra.rb', line 42

def self.class_key(cls)
  nesting = cls.class_eval("Module.nesting")
  nesting.pop
  nesting.join('::')
end

.expand_path(file) ⇒ Object



48
49
50
51
# File 'lib/parameters_extra.rb', line 48

def self.expand_path(file)
  file = File.expand_path(file)
  File.exist?(file) ? file : "#{file}.rb"
end

.load(file, require_file = true) ⇒ Object



16
17
18
19
# File 'lib/parameters_extra.rb', line 16

def self.load(file, require_file = true)
  require file if require_file
  register file
end

.parameters_for_method(method) ⇒ Object



21
22
23
24
# File 'lib/parameters_extra.rb', line 21

def self.parameters_for_method(method)
  k = class_key(method.owner)
  ClassMethodRegistry[k][method.name.to_sym] if ClassMethodRegistry.key?(k)
end

.parse(file, require_file = true) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/parameters_extra.rb', line 34

def self.parse(file, require_file = true)
  parser = RubyParser.new
  sexp = parser.process(File.read(expand_path(file)))
  parameters_extra = Processor.new
  parameters_extra.process(sexp)
  parameters_extra.methods
end

.register(file) ⇒ Object



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

def self.register(file)
  file = expand_path(file)
  unless FileRegistry.include?(file)
    FileRegistry << file
    parse(file).each { |cls, methods| ClassMethodRegistry[cls].add_methods!(methods) }
  end
end