alias_helper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in alias_helper.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ = AliasHelper
2
+
3
+ For some reason Rails does not appear to easily expose the aliases returned by
4
+ ActiveSupport::CoreExtensions::Module#alias_method_chain. This adds methods
5
+ for retrieving the aliases that are generated.
6
+
7
+ Author:: Clyde Law (mailto:clyde@futureadvisor.com)
8
+ License:: Released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "alias_helper/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "alias_helper"
7
+ s.version = AliasHelper::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Clyde Law"]
10
+ s.email = ["clyde@futureadvisor.com"]
11
+ s.homepage = %q{http://github.com/FutureAdvisor/alias_helper}
12
+ s.summary = %q{Adds methods for retrieving the aliases that are generated by ActiveSupport::CoreExtensions::Module#alias_method_chain.}
13
+ s.description = %q{For some reason Rails does not appear to easily expose the aliases returned by ActiveSupport::CoreExtensions::Module#alias_method_chain. This adds methods for retrieving the aliases that are generated.}
14
+
15
+ s.rubyforge_project = "alias_helper"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,3 @@
1
+ module AliasHelper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ module ActiveSupport::CoreExtensions::Module
2
+
3
+ # Given a target method and the feature name, returns the names of aliases
4
+ # that ActiveSupport::CoreExtensions::Module#alias_method_chain typically
5
+ # defines for the target method and feature.
6
+ def method_chain_aliases(target, feature)
7
+ # Strip out punctuation on predicates or bang methods since
8
+ # e.g. target?_without_feature is not a valid method name.
9
+ aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
10
+ [
11
+ "#{aliased_target}_with_#{feature}#{punctuation}".to_sym,
12
+ "#{aliased_target}_without_#{feature}#{punctuation}".to_sym
13
+ ]
14
+ end
15
+
16
+ # Given a target method and the feature name, returns the name of the alias
17
+ # that ActiveSupport::CoreExtensions::Module#alias_method_chain typically
18
+ # defines for the target method with the feature.
19
+ def method_alias_with_feature(target, feature)
20
+ method_chain_aliases(target, feature)[0]
21
+ end
22
+
23
+ # Given a target method and the feature name, returns the name of the alias
24
+ # that ActiveSupport::CoreExtensions::Module#alias_method_chain typically
25
+ # defines for the target method without the feature.
26
+ def method_alias_without_feature(target, feature)
27
+ method_chain_aliases(target, feature)[1]
28
+ end
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alias_helper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Clyde Law
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-19 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: For some reason Rails does not appear to easily expose the aliases returned by ActiveSupport::CoreExtensions::Module#alias_method_chain. This adds methods for retrieving the aliases that are generated.
22
+ email:
23
+ - clyde@futureadvisor.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.rdoc
34
+ - Rakefile
35
+ - alias_helper.gemspec
36
+ - lib/alias_helper.rb
37
+ - lib/alias_helper/version.rb
38
+ homepage: http://github.com/FutureAdvisor/alias_helper
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project: alias_helper
67
+ rubygems_version: 1.7.2
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Adds methods for retrieving the aliases that are generated by ActiveSupport::CoreExtensions::Module#alias_method_chain.
71
+ test_files: []
72
+