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: 'http://www.sanger.ac.uk/Users/mw4/ruby/rails/acts_as_descriptable',
version: '1.0',
author_link: 'http://www.sanger.ac.uk/Users/mw4/',
author_name: 'Matt Wood'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:


32
33
34
# File 'lib/acts_as_descriptable.rb', line 32

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

Instance Method Details

#add_descriptor(descriptor) ⇒ Object


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

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

#descriptor_hashObject


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

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

#descriptor_value(key) ⇒ Object


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

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

#descriptorsObject


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

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