Module: Transpose::Transposable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/transpose/transposable.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #transpose(klass) ⇒ Object (also: #transpose_to, #transpose_into)
- #transpose_instance(transposition_instance) ⇒ Object (also: #transpose_to_instance, #transpose_with_instance)
Instance Method Details
#transpose(klass) ⇒ Object Also known as: transpose_to, transpose_into
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/transpose/transposable.rb', line 17 def transpose(klass) transposition_instance = klass.is_a?(String) ? klass.constantize.new : klass.new raise ::Transpose::Errors::TransposerNotFound unless self.class.transposers.has_key?(transposition_instance.class.name) result = self.class.transposers[klass.to_s].inject(transposition_instance) do |transposition, hash_pair| transposition.__send__("#{hash_pair[1]}=", self.__send__(hash_pair[0])) transposition end result end |
#transpose_instance(transposition_instance) ⇒ Object Also known as: transpose_to_instance, transpose_with_instance
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/transpose/transposable.rb', line 32 def transpose_instance(transposition_instance) raise ::Transpose::TransposerNotFound unless self.class.transposers.has_key?(transposition_instance.class.name) result = self.class.transposers[transposition_instance.class.name].inject(transposition_instance) do |transposition, hash_pair| transposition.__send__("#{hash_pair[1]}=", self.__send__(hash_pair[0])) transposition end result end |