forked from nathanvda/actionwebservice
/
simple.rb
54 lines (46 loc) · 1.34 KB
/
simple.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
# encoding: UTF-8
module ActionWebService
# To send simple types across the wire, derive from ActionWebService::Simple,
# and use +base+ to declare the base type for it restriction and,
# use +restriction+ to declare valid W3C restriction element for SimpleType.
#
# ActionWebService::Simple should be used when you want to declare valid custom simple type
# to be used inside expects, returns and structured types
#
#
# There plenty documentation available at W3C Archives
# http://www.w3.org/TR/xmlschema-2/
#
# === Example
#
# class Gender < ActionWebService::Simple
# base :string
# restriction :enumeration, "male|female"
# end
#
#
class Simple
def initialize(value)
@value = value
end
class << self
def base(type)
type = type.to_s.camelize(:lower)
write_inheritable_attribute("xml_base", type)
class_eval <<-END
def xml_base; "#{type}"; end
END
end
def restriction_base
read_inheritable_attribute("xml_base") || ""
end
def restriction(type, value)
type = type.to_s.camelize(:lower)
write_inheritable_hash("simple_restrictions", type => value)
end
def restrictions
read_inheritable_attribute("simple_restrictions") || {}
end
end
end
end