Skip to content

Commit a14df27

Browse files
committed
declare a model
1 parent f0a497f commit a14df27

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

lib/my_mongoid.rb

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,52 @@
11
require "my_mongoid/version"
2+
require 'active_support/concern'
23

34
module MyMongoid
4-
# Your code goes here...
5+
6+
module Document
7+
extend ActiveSupport::Concern
8+
9+
@@models = []
10+
11+
included do
12+
extend ClassMethods
13+
14+
@@models << self
15+
16+
self.class_eval do
17+
attr_accessor :attributes
18+
19+
def read_attribute(key)
20+
@attributes[key]
21+
end
22+
23+
def write_attribute(key, value)
24+
@attributes[key] = value
25+
end
26+
end
27+
end
28+
29+
def initialize(attributes)
30+
raise ArgumentError, 'It is not a hash' unless attributes.is_a?(Hash)
31+
@attributes = attributes
32+
33+
MyMongoid.models ||= []
34+
35+
end
36+
37+
def MyMongoid.models
38+
@@models
39+
end
40+
41+
module ClassMethods
42+
def is_mongoid_model?
43+
true
44+
end
45+
46+
def field
47+
48+
end
49+
end
50+
end
51+
552
end

my_mongoid_spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 2b9ec2cd424be18fd9b63a01ab77b9a49076796c

0 commit comments

Comments
 (0)