Module: Protector::Adapters::ActiveRecord::Base::ClassMethods

Defined in:
lib/protector/adapters/active_record/base.rb

Instance Method Summary collapse

Instance Method Details

#define_method_attribute(name) ⇒ Object

Wraps every .field method with a check against DSL::Meta::Box#readable?



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/protector/adapters/active_record/base.rb', line 74

def define_method_attribute(name)
  super

  # Show some <3 to composite primary keys
  unless (primary_key == name || Array(primary_key).include?(name))
    generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
      alias_method #{"#{name}_unprotected".inspect}, #{name.inspect}

      def #{name}
        if !protector_subject? || protector_meta.readable?(#{name.inspect})
          #{name}_unprotected
        else
          nil
        end
      end
    STR
  end
end

#protector_metaObject

Storage of DSL::Meta



65
66
67
68
69
70
71
# File 'lib/protector/adapters/active_record/base.rb', line 65

def protector_meta
  @protector_meta ||= Protector::DSL::Meta.new(
    Protector::Adapters::ActiveRecord,
    self,
    self.column_names
  )
end