Class: Witness::Base
- Inherits:
-
Object
- Object
- Witness::Base
- Defined in:
- lib/witness/base.rb
Constant Summary collapse
- VALID_TYPES =
[:string, :integer, :symbol]
Class Method Summary collapse
- .action(*action_names) ⇒ Object
- .column(column, *attr_names) ⇒ Object
- .validates_presence_of(*attr_names) ⇒ Object
- .validates_signature_of(*attr_names) ⇒ Object
Class Method Details
.action(*action_names) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/witness/base.rb', line 12 def self.action(*action_names) [*action_names].each do |action_name| self.actions << action_name.to_sym class_eval <<-end_eval def self.#{action_name.to_sym}(provided_params, key = nil) command = "#{action_name}".to_sym provided_params.merge!(:key => key) if key.present? construct(provided_params.update(:command => command)) end end_eval end end |
.column(column, *attr_names) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/witness/base.rb', line 26 def self.column(column, *attr_names) configuration = { :type => :string, :name => column.to_s.humanize } configuration.update(attr_names.) self.columns[column] = configuration attr_accessor column end |
.validates_presence_of(*attr_names) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/witness/base.rb', line 35 def self.validates_presence_of(*attr_names) configuration = { :on => self.actions } configuration.update(attr_names.) [*configuration[:on]].each do |on| self.validates_presence[on] ||= [] [*attr_names].each do |attr_name| self.validates_presence[on] << attr_name end end end |
.validates_signature_of(*attr_names) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/witness/base.rb', line 48 def self.validates_signature_of(*attr_names) configuration = { :on => self.actions } configuration.update(attr_names.) [*configuration[:on]].each do |on| self.validates_signature[on] ||= [] [*attr_names].each do |attr_name| self.validates_signature[on] << attr_name end end column :signature column :key end |