Permalink
Browse files

Change to .class_attribute for AS 3.1

  • Loading branch information...
1 parent d270aec commit 70916df66e24618df26a1535c0784b2e7a6bbf8d @leshill committed Jun 18, 2011
View
@@ -11,37 +11,51 @@ PATH
GEM
remote: http://rubygems.org/
specs:
- activemodel (3.0.7)
- activesupport (= 3.0.7)
+ activemodel (3.0.9)
+ activesupport (= 3.0.9)
builder (~> 2.1.2)
i18n (~> 0.5.0)
- activesupport (3.0.7)
+ activesupport (3.0.9)
+ archive-tar-minitar (0.5.2)
bson (1.3.1)
bson_ext (1.3.1)
builder (2.1.2)
- cucumber (0.10.0)
+ columnize (0.3.3)
+ cucumber (0.10.7)
builder (>= 2.1.2)
- diff-lcs (~> 1.1.2)
- gherkin (~> 2.3.2)
- json (~> 1.4.6)
- term-ansicolor (~> 1.0.5)
+ diff-lcs (>= 1.1.2)
+ gherkin (~> 2.4.0)
+ json (>= 1.4.6)
+ term-ansicolor (>= 1.0.5)
diff-lcs (1.1.2)
- gherkin (2.3.3)
- json (~> 1.4.6)
+ gherkin (2.4.0)
+ json (>= 1.4.6)
i18n (0.5.0)
- json (1.4.6)
+ json (1.5.2)
+ linecache19 (0.5.12)
+ ruby_core_source (>= 0.1.4)
mongo (1.3.1)
bson (>= 1.3.1)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.1)
- rspec-expectations (2.5.0)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.5.0)
+ rspec-mocks (2.6.0)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
term-ansicolor (1.0.5)
- tzinfo (0.3.27)
+ tzinfo (0.3.28)
PLATFORMS
ruby
@@ -50,3 +64,4 @@ DEPENDENCIES
cucumber (>= 0.10.0)
mongo_doc!
rspec (>= 2.5.0)
+ ruby-debug19 (>= 0.11.6)
@@ -13,7 +13,7 @@ def embed(*args)
end
args.each do |name|
- _associations << name unless _associations.include?(name)
+ _add_association(name)
attr_reader name
@@ -41,7 +41,7 @@ def embed_many(*args)
end
args.each do |name|
- _associations << name unless _associations.include?(name)
+ _add_association(name)
define_method("#{name}") do
association = instance_variable_get("@#{name}")
@@ -75,7 +75,7 @@ def embed_hash(*args)
end
args.each do |name|
- _associations << name unless _associations.include?(name)
+ _add_association(name)
define_method("#{name}") do
association = instance_variable_get("@#{name}")
@@ -2,9 +2,9 @@ module MongoDoc
module Attributes
def self.included(klass)
klass.class_eval do
- class_inheritable_array :_keys
+ class_attribute :_keys
self._keys = []
- class_inheritable_array :_associations
+ class_attribute :_associations
self._associations = []
attr_accessor :_id
@@ -35,6 +35,14 @@ def self.extended(klass)
end
end
+ def _add_key(key)
+ self._keys += [key] unless _keys.include?(key)
+ end
+
+ def _add_association(association)
+ self._associations += [association] unless _associations.include?(association)
+ end
+
def _attributes
_keys + _associations
end
@@ -45,7 +53,7 @@ def attr_accessor_with_mongo(*args)
default = opts.delete(:default)
type = opts.delete(:type)
args.each do |name|
- _keys << name unless _keys.include?(name)
+ _add_key(name)
attr_writer name
unless default.nil?
@@ -82,7 +82,7 @@ def references_many(*args)
def references_many_by_dbref(objects_name)
refs_name = "#{objects_name.singularize}_refs"
- _keys << refs_name unless _keys.include?(refs_name)
+ _add_key(refs_name)
module_eval(<<-RUBY, __FILE__, __LINE__)
def #{objects_name}=(objects) # def addresses=(objects)
@@ -108,7 +108,7 @@ def #{refs_name} # def address_refs
def references_many_by_id(klass, objects_name)
ids_name = "#{objects_name.singularize}_ids"
- _keys << ids_name unless _keys.include?(ids_name)
+ _add_key(ids_name)
module_eval(<<-RUBY, __FILE__, __LINE__)
def #{objects_name}=(objects) # def addresses=(objects)
@@ -10,7 +10,7 @@ module Timestamps
# +updated_at+:: set on every save
def timestamps!
[:created_at, :updated_at].each do |name|
- _keys << name unless _keys.include?(name)
+ _add_key(name)
attr_reader name
class_eval(<<-RUBY, __FILE__, __LINE__)
def #{name}=(value) # def created_at=(value)
View
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('tzinfo', ['>= 0.3.22'])
s.add_development_dependency('cucumber', ['>= 0.10.0'])
s.add_development_dependency('rspec', ['>= 2.5.0'])
+ s.add_development_dependency('ruby-debug19', ['>= 0.11.6'])
end
@@ -1,7 +1,7 @@
require 'spec_helper'
describe "MongoDoc::Attributes attributes accessor" do
- class AttributesTest
+ class AttributesAccessorTest
include MongoDoc::Attributes
attr_accessor :name
@@ -11,7 +11,7 @@ class AttributesTest
context "#attributes" do
subject do
- AttributesTest.new.attributes
+ AttributesAccessorTest.new.attributes
end
it "returns a hash of the given attributes" do
@@ -22,7 +22,7 @@ class AttributesTest
end
context "#attributes=" do
- let(:object) { AttributesTest.new }
+ let(:object) { AttributesAccessorTest.new }
it "sets attributes from a hash" do
name = 'name'
@@ -276,8 +276,6 @@ class BSONTest
end
class BSONDerived < BSONTest
- include MongoDoc::Document
-
attr_accessor :derived
end

0 comments on commit 70916df

Please sign in to comment.