7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/rails_pattern_view.rb', line 7
def use_pattern(pattern, opts = {})
only = opts[:only] || []
except = opts[:except] || []
mapping = opts[:mapping] || {}
template = opts[:template] || {}
raise 'cannot mix `template` & `mapping`' if template.present? && mapping.present?
raise 'cannot mix `only` & `except`' if only.present? && except.present?
raise '`only` must be Array type' if !only.is_a? Array
raise '`except` must be Array type' if !except.is_a? Array
raise '`mapping` must be Hash type' if !mapping.is_a? Hash
actions = (only.present? ? only : action_methods.to_a) - except
mapping[template] = actions if template.present?
mappings = resolve_mapping(mapping)
define_method(:pattern_name) { pattern }
define_method(:pattern_actions_mapping) { mappings }
private :pattern_name, :pattern_actions_mapping
before_filter :filter_render, :only => actions
end
|