/
fields.rb
59 lines (55 loc) · 1.05 KB
/
fields.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module Redisted
class Base
def fields
self.class.fields
end
def scopes
self.class.scopes
end
private
def init_fields
end
class << self
public
#
# Setup
#
def field value,options={}
options[:type]||=:string
fields[value]=options
end
def fields
@fields||={}
@fields
end
def fields= val
@fields=val
end
def scopes
@scopes||={}
@scopes
end
def scopes= val
@scopes=val
end
def scope name,options
scopes[name]=lambdafi_field(options)
end
private
def read_attribute_for_validation key
get_attr key
end
def lambdafi_field options
lambda do |*args|
if options.respond_to? :call
options.call(*args)
elsif options.is_a? Symbol
args[0].send(options,*args)
else
options # An integer or other constant value
end
end
end
end
end
end