module Hypostasis::Shared::Fields::ClassMethods

Public Instance Methods

field(name, options = {}) click to toggle source
# File lib/hypostasis/shared/fields.rb, line 10
def field(name, options = {})
  register_field(name.to_sym)
  create_accessors(name.to_s, options)
end

Private Instance Methods

create_accessors(name, options) click to toggle source
# File lib/hypostasis/shared/fields.rb, line 23
def create_accessors(name, options)
  self.class_eval do
    define_method(name) { @fields[name.to_sym] || nil }
    define_method("#{name}=") {|value| @fields[name.to_sym] = value}
  end
end
register_field(name) click to toggle source
# File lib/hypostasis/shared/fields.rb, line 17
def register_field(name)
  registered_fields = fields
  registered_fields << name.to_sym
  fields = registered_fields
end