From af5301089f38b9aad9a92424d5fa8f9a9b27c4e1 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 17 Jun 2009 20:36:21 -0500 Subject: Add simple attribute implementation backed by ivars --- activemodel/lib/active_model.rb | 1 + activemodel/lib/active_model/attributes.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 activemodel/lib/active_model/attributes.rb (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb index f8e5725e9c..048f542239 100644 --- a/activemodel/lib/active_model.rb +++ b/activemodel/lib/active_model.rb @@ -26,6 +26,7 @@ $:.unshift(activesupport_path) if File.directory?(activesupport_path) require 'active_support' module ActiveModel + autoload :Attributes, 'active_model/attributes' autoload :Base, 'active_model/base' autoload :DeprecatedErrorMethods, 'active_model/deprecated_error_methods' autoload :Errors, 'active_model/errors' diff --git a/activemodel/lib/active_model/attributes.rb b/activemodel/lib/active_model/attributes.rb new file mode 100644 index 0000000000..4665525281 --- /dev/null +++ b/activemodel/lib/active_model/attributes.rb @@ -0,0 +1,17 @@ +require 'active_support/core_ext/object/instance_variables' + +module ActiveModel + module Attributes + def attributes + instance_values + end + + def read_attribute(attr_name) + instance_variable_get(:"@#{attr_name}") + end + + def write_attribute(attr_name, value) + instance_variable_set(:"@#{attr_name}", value) + end + end +end -- cgit v1.2.3