Parent

Files

Module

Public Instance Methods

alias_for(original, *aliases) click to toggle source
# File lib/sugar-high/alias.rb, line 70
def alias_for(original, *aliases)
  pluralize = last_option(aliases)[:pluralize]
  singularize = last_option(aliases)[:singularize]

  class_eval "alias_method :#{original.to_s.singularize}, :#{original}" if singularize
  class_eval "alias_method :#{original.to_s.pluralize}, :#{original}" if pluralize

  aliases.flatten.select_labels.each do |alias_meth|
    class_eval "alias_method :#{alias_meth}, :#{original}"
    class_eval "alias_method :#{alias_meth.to_s.pluralize}, :#{original}" if pluralize
    class_eval "alias_method :#{alias_meth.to_s.singularize}, :#{original}" if singularize
  end
end
Also aliased as: aliases_for
alias_hash(hash) click to toggle source
# File lib/sugar-high/alias.rb, line 58
def alias_hash(hash)
  pluralize = hash.delete(:pluralize)
  singularize = hash.delete(:singularize)
  # option = :pluralize => pluralize, :singularize => singularize
  
  hash.each_pair do |original, alias_meth|
    alias_for original, alias_meth
    alias_for original.to_s.singularize, alias_meth.to_s.singularize, :singularize => true if singularize
    alias_for original.to_s.pluralize, alias_meth.to_s.pluralize, :pluralize => true if pluralize
  end
end
alias_methods(name, original, aliases, config_options) click to toggle source
# File lib/sugar-high/alias.rb, line 46
def alias_methods name, original, aliases, config_options
  aliases.each do |alias_name|                       
    new_alias     = make_name(name, alias_name.to_s, config_options)
    original_name = make_name(name, original.to_s, config_options)
    begin         
      alias_method new_alias, original_name
    rescue
      raise ArgumentError, "Error creating alias for ##{original_name} with ##{new_alias}"
    end        
  end
end
aliases_for(original, *aliases) click to toggle source
Alias for: alias_for
demodulize() click to toggle source
Alias for: last_name
extends_and_includes(*module_names) click to toggle source
extends_and_includes_from(module_name, *sub_modules) click to toggle source
includes_and_extends(*module_names) click to toggle source
# File lib/sugar-high/includes.rb, line 26
def includes_and_extends *module_names
  includes module_names
  extends module_names
end
Also aliased as: extends_and_includes
includes_and_extends_from(module_name, *sub_modules) click to toggle source
# File lib/sugar-high/includes.rb, line 31
def includes_and_extends_from module_name, *sub_modules
  includes module_name, *sub_modules
  extends module_name, *sub_modules
end
Also aliased as: extends_and_includes_from
last_name() click to toggle source
# File lib/sugar-high/module.rb, line 4
def last_name
  # name.gsub /^(.*)::/, ''
  name.demodulize
end
Also aliased as: demodulize
multi_alias(*args) click to toggle source

multi_alias name, :create => :new, :insert_into => [:inject_into, :update], :read => :X_content

:options => :after

create_xxx becomes new_xxx insert_into_xxx becomes inject_into_xxx and update_xxx read_xxx becomes xxx_content (overriding default :after action to insert at the X)

# File lib/sugar-high/alias.rb, line 16
def multi_alias *args
  name = case args.first
  when Symbol, String            
    args.first.to_s
  when Hash    
    # default is :after
    args.first[:_before_] ? :before : :after
  end
  
  if name.kind_of? Symbol
    config_options = name
    options = args.first
    name = options[:"_#{name}_"]
  else
    options = args[1]
  end          
  
  raise ArgumentError, "Name of method pattern to alias not specified. Please pass name as either first argument or as :_before_ or :_after_ option" if !name

  options.delete(:_after_)
  options.delete(:_before_)
  direction = options.delete(:_direction_)
  
  options = options.hash_revert if direction == :reverse
  
  options.each_pair do |original, aliases|
    alias_methods name.to_sym, original, [aliases].flatten, config_options
  end            
end

Protected Instance Methods

make_name(name, alias_name, config_options) click to toggle source
# File lib/sugar-high/alias.rb, line 87
def make_name name, alias_name, config_options
  return alias_name.gsub(/X/, name.to_s) if alias_name =~ /X/    
  case config_options
  when :before
    "#{name}_#{alias_name}"
  else # default
    "#{alias_name}_#{name}"
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.