Class: Transmutable::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/transmutable/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Base

Returns a new instance of Base.



23
24
25
# File 'lib/transmutable/base.rb', line 23

def initialize(model)
  @model = model
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



3
4
5
# File 'lib/transmutable/base.rb', line 3

def model
  @model
end

Class Method Details

.add_to_transmute(*methods) ⇒ Object



5
6
7
8
9
# File 'lib/transmutable/base.rb', line 5

def self.add_to_transmute(*methods)
  define_method :transmute_addons do
    methods
  end
end

.remove_from_transmute(*methods) ⇒ Object



11
12
13
14
15
# File 'lib/transmutable/base.rb', line 11

def self.remove_from_transmute(*methods)
  define_method :transmute_skips do
    methods
  end
end

.serialize_attrs(*methods) ⇒ Object



17
18
19
20
21
# File 'lib/transmutable/base.rb', line 17

def self.serialize_attrs(*methods)
  define_method :default_attrs do
    methods
  end
end

Instance Method Details

#transmuteObject



27
28
29
# File 'lib/transmutable/base.rb', line 27

def transmute
  Hash[serialize_methods.map { |attribute| [attribute, model.send(attribute)] }]
end