Module: TaskMapper::Provider::Common
- Included in:
- Base::Comment, Base::Project, Base::Ticket
- Defined in:
- lib/taskmapper/common.rb
Overview
Common module contains method definitions common to all or most of the models
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Automatic extension of class methods on include.
Instance Method Summary collapse
-
#destroy ⇒ Object
Delete this project Returns true (success) or false(failure).
-
#initialize(*options) ⇒ Object
The initializer It tries to do a default system for ActiveResource-based api providers.
- #respond_to?(symbol, include_private = false) ⇒ Boolean
-
#save ⇒ Object
Save changes to this project Returns true (success) or false (failure) or nil (no changes).
-
#update!(*options) ⇒ Object
Update the something and save As opposed to update which just updates the attributes.
Class Method Details
.included(base) ⇒ Object
Automatic extension of class methods on include
21 22 23 |
# File 'lib/taskmapper/common.rb', line 21 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#destroy ⇒ Object
Delete this project Returns true (success) or false(failure)
67 68 69 70 71 72 73 |
# File 'lib/taskmapper/common.rb', line 67 def destroy if @system_data and @system_data[:client] and @system_data[:client].respond_to?(:destroy) return @system_data[:client].destroy else raise TaskMapper::Exception.new("#{self.class.name}::#{this_method} method must be implemented by the provider") end end |
#initialize(*options) ⇒ Object
The initializer It tries to do a default system for ActiveResource-based api providers
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/taskmapper/common.rb', line 27 def initialize(*) @system_data ||= {} @cache ||= {} first = .shift case first when Hash super(first.to_hash) else @system_data[:client] = first self. ||= @system_data[:client]. if @system_data[:client]. super(first.attributes) end end |
#respond_to?(symbol, include_private = false) ⇒ Boolean
75 76 77 78 79 |
# File 'lib/taskmapper/common.rb', line 75 def respond_to?(symbol, include_private = false) result = super(symbol) return true if result or @system_data.nil? or @system_data[:client].nil? @system_data[:client].respond_to?(symbol, include_private) end |
#save ⇒ Object
Save changes to this project Returns true (success) or false (failure) or nil (no changes)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/taskmapper/common.rb', line 50 def save if @system_data and (something = @system_data[:client]) and something.respond_to?(:attributes) changes = 0 something.attributes.each do |k, v| if self.send(k) != v something.send(k + '=', self.send(k)) changes += 1 end end something.save if changes > 0 else raise TaskMapper::Exception.new("#{self.class.name}::#{this_method} method must be implemented by the provider") end end |
#update!(*options) ⇒ Object
Update the something and save As opposed to update which just updates the attributes
43 44 45 46 |
# File 'lib/taskmapper/common.rb', line 43 def update!(*) update(*) save end |