Sha256: 1774fabceafa6aeb21dca9bb8eaeff746eadd5ad4371dc5d5310f2c489ec1fe8

Contents?: true

Size: 722 Bytes

Versions: 6

Compression:

Stored size: 722 Bytes

Contents

# Creates aliases of class methods. Expects a hash of classes/modules mapped to a hash of class methods and their aliases
# i.e. {'Date'=>{'today'=>'t'}}.
class Alias::Creators::ClassMethodCreator < Alias::Creator
  map do |config|
    config.inject([]) {|t,(klass,aliases)|
      t += aliases.map {|k,v| {:class=>klass, :name=>k, :alias=>v} }
    }
  end

  valid :class, :if=>:class
  valid :class_method, :if=>:class_method, :with=>[:class, :name]
  valid :alias, :unless=>:class_method, :with=>[:class, :alias], :optional=>true

  generate do |aliases|
    aliases.map {|e|
      "#{class_or_module(e[:class])} ::#{e[:class]}; class<<self; alias_method :#{e[:alias]}, :#{e[:name]}; end; end"
    }.join("\n")
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
cldwalker-alias-0.2.0 lib/alias/creators/class_method_creator.rb
cldwalker-alias-0.2.1 lib/alias/creators/class_method_creator.rb
alias-0.2.3 lib/alias/creators/class_method_creator.rb
alias-0.2.2 lib/alias/creators/class_method_creator.rb
alias-0.2.0 lib/alias/creators/class_method_creator.rb
alias-0.2.1 lib/alias/creators/class_method_creator.rb