Module: PivotalTracker::Validation

Included in:
Project, Story, Task
Defined in:
lib/pivotal-tracker/validation.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pivotal-tracker/validation.rb', line 32

def self.included(klass)
  klass.class_eval do
    instance_methods = klass.instance_methods.map {|name| name.to_sym}
    if instance_methods.include?(:create)
      alias_method :create_without_validations, :create
      alias_method :create, :create_with_validations
    end

    if instance_methods.include?(:update)
      alias_method :update_without_validations, :update
      alias_method :update, :update_with_validations
    end
  end
end

Instance Method Details

#create_with_validationsObject



47
48
49
50
51
52
53
54
# File 'lib/pivotal-tracker/validation.rb', line 47

def create_with_validations
  begin
    create_without_validations
  rescue RestClient::UnprocessableEntity => e
    errors.add_from_xml e.response
    self
  end
end

#errorsObject



65
66
67
# File 'lib/pivotal-tracker/validation.rb', line 65

def errors
  @errors ||= Errors.new
end

#update_with_validations(attrs = {}) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/pivotal-tracker/validation.rb', line 56

def update_with_validations(attrs={})
  begin
    update_without_validations attrs
  rescue RestClient::UnprocessableEntity => e
    errors.add_from_xml e.response
    self
  end
end