Methods
- A
-
- C
-
- F
-
- H
-
- I
-
- K
-
- M
-
- N
-
- P
-
- R
-
- S
-
- T
-
- U
-
- W
-
Attributes
Class Protected methods
check_class_collision(options={})
Add a class collisions name to be checked on class initialization. You can
supply a hash with a :prefix or :suffix to be tested.
Examples
check_class_collision :suffix => "Observer"
If the generator is invoked with class name Admin, it will check for the
presence of “AdminObserver”.
Source: show
| on GitHub
179: def self.check_class_collision(options={})
180: define_method :check_class_collision do
181: name = if self.respond_to?(:controller_class_name)
182: controller_class_name
183: else
184: class_name
185: end
186:
187: class_collisions "#{options[:prefix]}#{name}#{options[:suffix]}"
188: end
189: end
Instance Public methods
template(source, *args, &block)
Source: show
| on GitHub
25: def template(source, *args, &block)
26: inside_template do
27: super
28: end
29: end
Instance Protected methods
Tries to retrieve the application name or simple return application.
Source: show
| on GitHub
144: def application_name
145: if defined?(Rails) && Rails.application
146: Rails.application.class.name.split('::').first.underscore
147: else
148: "application"
149: end
150: end
Source: show
| on GitHub
96: def class_name
97: (class_path + [file_name]).map!{ |m| m.camelize }.join('::')
98: end
Source: show
| on GitHub
77: def class_path
78: inside_template? || !namespaced? ? regular_class_path : namespaced_class_path
79: end
Source: show
| on GitHub
73: def file_path
74: @file_path ||= (class_path + [file_name]).join('/')
75: end
Source: show
| on GitHub
100: def human_name
101: @human_name ||= singular_name.humanize
102: end
Source: show
| on GitHub
108: def i18n_scope
109: @i18n_scope ||= file_path.gsub('/', '.')
110: end
indent(content, multiplier = 2)
Source: show
| on GitHub
44: def indent(content, multiplier = 2)
45: spaces = " " * multiplier
46: content = content.each_line.map {|line| "#{spaces}#{line}" }.join
47: end
Source: show
| on GitHub
123: def index_helper
124: uncountable? ? "#{plural_table_name}_index" : plural_table_name
125: end
Source: show
| on GitHub
54: def inside_template
55: @inside_template = true
56: yield
57: ensure
58: @inside_template = false
59: end
Source: show
| on GitHub
61: def inside_template?
62: @inside_template
63: end
Returns Ruby 1.9 style key-value pair if current code is running on Ruby
1.9.x. Returns the old-style (with hash rocket) otherwise.
Source: show
| on GitHub
193: def key_value(key, value)
194: if options[:old_style_hash] || RUBY_VERSION < '1.9'
195: ":#{key} => #{value}"
196: else
197: "#{key}: #{value}"
198: end
199: end
module_namespacing(&block)
Wrap block with namespace of current application if namespace exists and is
not skipped
Source: show
| on GitHub
38: def module_namespacing(&block)
39: content = capture(&block)
40: content = wrap_with_namespace(content) if namespaced?
41: concat(content)
42: end
Source: show
| on GitHub
65: def namespace
66: Rails::Generators.namespace
67: end
Source: show
| on GitHub
69: def namespaced?
70: !options[:skip_namespace] && namespace
71: end
Source: show
| on GitHub
89: def namespaced_class_path
90: @namespaced_class_path ||= begin
91: namespace_path = namespace.name.split("::").map {|m| m.underscore }
92: namespace_path + @class_path
93: end
94: end
Source: show
| on GitHub
85: def namespaced_file_path
86: @namespaced_file_path ||= namespaced_class_path.join("/")
87: end
Source: show
| on GitHub
135: def plural_file_name
136: @plural_file_name ||= file_name.pluralize
137: end
Source: show
| on GitHub
104: def plural_name
105: @plural_name ||= singular_name.pluralize
106: end
Source: show
| on GitHub
131: def plural_table_name
132: @plural_table_name ||= (pluralize_table_names? ? table_name : table_name.pluralize)
133: end
Source: show
| on GitHub
165: def pluralize_table_names?
166: !defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names
167: end
Source: show
| on GitHub
81: def regular_class_path
82: @class_path
83: end
Source: show
| on GitHub
139: def route_url
140: @route_url ||= class_path.collect{|dname| "/" + dname }.join('') + "/" + plural_file_name
141: end
Source: show
| on GitHub
127: def singular_table_name
128: @singular_table_name ||= (pluralize_table_names? ? table_name.singularize : table_name)
129: end
Source: show
| on GitHub
112: def table_name
113: @table_name ||= begin
114: base = pluralize_table_names? ? plural_name : singular_name
115: (class_path + [base]).join('_')
116: end
117: end
Source: show
| on GitHub
119: def uncountable?
120: singular_name == plural_name
121: end
wrap_with_namespace(content)
Source: show
| on GitHub
49: def wrap_with_namespace(content)
50: content = indent(content).chomp
51: "module #{namespace.name}\n#{content}\nend\n"
52: end