Module: ActsAsActsAs::ActsAsShortcuts

Defined in:
lib/acts_as_acts_as/acts_as_shortcuts.rb

Instance Method Summary collapse

Instance Method Details

#require_class_methods(*method_list) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/acts_as_acts_as/acts_as_shortcuts.rb', line 21

def require_class_methods(*method_list)
  method_list.each do |required_method| 
    unless methods.include?(required_method.to_s) 
      raise "Model #{self.to_s} must define class method #{required_method}"
    end
  end
end

#require_columns(*column_and_type_pairs) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/acts_as_acts_as/acts_as_shortcuts.rb', line 29

def require_columns(*column_and_type_pairs)
  column_problems = []
  column_and_type_pairs.each do |req_colname, req_type|
    c = columns.find { |c| c.name == req_colname.to_s } 
    if c.nil?
      column_problems << "Model #{self.to_s} must have column #{req_colname}"
      next
    elsif c.type != req_type
      column_problems << "Column #{req_colname} must have #{req_type} type, has #{c.type}"
    end
  end
  raise column_problems.join('; ') unless column_problems.empty?
end

#require_methods(*method_list) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/acts_as_acts_as/acts_as_shortcuts.rb', line 13

def require_methods(*method_list)
  method_list.each do |required_method| 
    unless instance_methods.include?(required_method.to_s) 
      raise "Model #{self.to_s} must define #{required_method}"
    end
  end
end

#require_parameters(options, *options_list) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/acts_as_acts_as/acts_as_shortcuts.rb', line 4

def require_parameters(options, *options_list)
  missing_options = (options_list - options.keys) # would convert to_s here, but people may not convert which would just hide bugs
  if missing_options.blank?
    true
  else
    raise "Model #{self.to_s} must pass options that include #{missing_options.inspect}"
  end
end