Module: ActsAsDescriptable

Included in:
LabEvent
Defined in:
lib/acts_as_descriptable.rb

Overview

name: ‘acts_as_descriptoable’, description: ‘Allows model fields and values to be dynamically extended.’, homepage: ‘www.sanger.ac.uk/Users/mw4/ruby/rails/acts_as_descriptable’, version: ‘1.0’, author_link: ‘www.sanger.ac.uk/Users/mw4/’, author_name: ‘Matt Wood’

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



35
36
37
# File 'lib/acts_as_descriptable.rb', line 35

def self.included(base)
  base.class_eval { serialize :descriptors }
end

Instance Method Details

#add_descriptor(descriptor) ⇒ Object



47
48
49
# File 'lib/acts_as_descriptable.rb', line 47

def add_descriptor(descriptor)
  write_attribute(:descriptors, descriptor_hash.merge(descriptor.name => descriptor.value))
end

#descriptor_hashObject



51
52
53
# File 'lib/acts_as_descriptable.rb', line 51

def descriptor_hash
  read_attribute(:descriptors) || {}
end

#descriptor_value(key) ⇒ Object



43
44
45
# File 'lib/acts_as_descriptable.rb', line 43

def descriptor_value(key)
  descriptor_hash.fetch(key, '')
end

#descriptorsObject



39
40
41
# File 'lib/acts_as_descriptable.rb', line 39

def descriptors
  descriptor_hash.map { |field, value| Descriptor.new(name: field, value: value) }
end