class PolicyMachineStorageAdapter::ActiveRecord::PolicyElement

Attributes

extra_attributes_hash[RW]

Public Instance Methods

method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/policy_machine_storage_adapters/active_record.rb, line 31
def method_missing(meth, *args, &block)
  methodize_extra_attributes_hash
  if respond_to?(meth)
    send(meth, *args)
  elsif meth.to_s[-1] == '='
    @extra_attributes_hash[meth.to_s] = args.first
    methodize_extra_attributes_hash
  else
    super
  end
end
methodize_extra_attributes_hash() click to toggle source
# File lib/policy_machine_storage_adapters/active_record.rb, line 48
def methodize_extra_attributes_hash
  @extra_attributes_hash = JSON.parse(self.extra_attributes, quirks_mode: true) if self.extra_attributes
  @extra_attributes_hash ||= {}
  @extra_attributes_hash.extract!(*self.class.column_names).each do |key, value|
    send("#{key}=", value) unless value.nil?
  end
  @extra_attributes_hash.each do |key, value|
    define_singleton_method key, lambda {@extra_attributes_hash[key.to_s]}
    define_singleton_method "#{key}=", lambda { | value | @extra_attributes_hash[key.to_s] = value }
  end
end
respond_to_missing?(meth, *args) click to toggle source
Calls superclass method
# File lib/policy_machine_storage_adapters/active_record.rb, line 43
def respond_to_missing?(meth, *args)
  methodize_extra_attributes_hash unless @extra_attributes_hash
  @extra_attributes_hash[meth.to_s] || super
end
serialize_extra_attributes_hash() click to toggle source
# File lib/policy_machine_storage_adapters/active_record.rb, line 60
def serialize_extra_attributes_hash
  methodize_extra_attributes_hash unless @extra_attributes_hash
  self.extra_attributes = extra_attributes_hash.to_json
end