Module: RailsPatternView::ClassMethods

Defined in:
lib/rails_pattern_view.rb

Instance Method Summary collapse

Instance Method Details

#use_pattern(pattern, opts = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rails_pattern_view.rb', line 7

def use_pattern(pattern, opts = {})
  only    = opts[:only]    || []
  except  = opts[:except]  || []
  mapping = opts[:mapping] || {}
  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
  mappings = resolve_mapping(mapping)

  define_method(:pattern_name) { pattern }
  define_method(:pattern_actions_mapping) { mappings }

  private :pattern_name, :pattern_actions_mapping
  actions = (only.present? ? only : action_methods.to_a) - except
  before_filter :filter_render, :only => actions
end