Module: Merritt::Manifest::Field

Included in:
Merritt::Manifest::Fields::Object
Defined in:
lib/merritt/manifest/fields.rb

Overview

Mixin for field enumerations

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Implemented to inject ClassMethods into field enumerations that include this module



34
35
36
# File 'lib/merritt/manifest/fields.rb', line 34

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#field_nameString



21
22
23
# File 'lib/merritt/manifest/fields.rb', line 21

def field_name
  value
end

#prefixObject

The prefix for this field



26
27
28
29
30
31
# File 'lib/merritt/manifest/fields.rb', line 26

def prefix
  @prefix ||= begin
    prefix, name = value.split(':')
    prefix if name # if we didn't find a name, then there's no ':' and hence no prefix
  end
end

#readerObject

Gets the reader method for this field



10
11
12
# File 'lib/merritt/manifest/fields.rb', line 10

def reader
  @reader ||= key.downcase
end

#value_from(obj) ⇒ Object

Reads the value of this field from the specified object, if available



15
16
17
18
# File 'lib/merritt/manifest/fields.rb', line 15

def value_from(obj)
  return unless obj.respond_to?(reader)
  obj.send(reader)
end