Class: Seahorse::Type
- Inherits:
-
Object
show all
- Defined in:
- lib/seahorse/type.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Type
Returns a new instance of Type.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/seahorse/type.rb', line 10
def initialize(*args)
name, opts = nil, {}
if args.size == 0
name = type
elsif args.size == 2
name, opts = args.first, args.last
elsif Hash === args.first
opts = args.first
else
name = args.first
end
self.name = name.to_s
opts.each {|k, v| send("#{k}=", v) }
end
|
Instance Attribute Details
#as ⇒ Object
Returns the value of attribute as.
3
4
5
|
# File 'lib/seahorse/type.rb', line 3
def as
@as
end
|
#documentation ⇒ Object
Returns the value of attribute documentation.
4
5
6
|
# File 'lib/seahorse/type.rb', line 4
def documentation
@documentation
end
|
Returns the value of attribute header.
3
4
5
|
# File 'lib/seahorse/type.rb', line 3
def
@header
end
|
#location ⇒ Object
Returns the value of attribute location.
3
4
5
|
# File 'lib/seahorse/type.rb', line 3
def location
@location
end
|
#model ⇒ Object
Returns the value of attribute model.
3
4
5
|
# File 'lib/seahorse/type.rb', line 3
def model
@model
end
|
#name ⇒ Object
Returns the value of attribute name.
3
4
5
|
# File 'lib/seahorse/type.rb', line 3
def name
@name
end
|
#required ⇒ Object
Returns the value of attribute required.
3
4
5
|
# File 'lib/seahorse/type.rb', line 3
def required
@required
end
|
#uri ⇒ Object
Returns the value of attribute uri.
3
4
5
|
# File 'lib/seahorse/type.rb', line 3
def uri
@uri
end
|
Class Method Details
.inspect ⇒ Object
8
|
# File 'lib/seahorse/type.rb', line 8
def self.inspect; "Type(#{type})" end
|
.type ⇒ Object
6
|
# File 'lib/seahorse/type.rb', line 6
def self.type; @type || name.to_s.underscore.gsub(/_type$|^.+\//, '') end
|
.type=(v) ⇒ Object
7
|
# File 'lib/seahorse/type.rb', line 7
def self.type=(v) @type = v end
|
Instance Method Details
#add(shape) ⇒ Object
51
52
53
|
# File 'lib/seahorse/type.rb', line 51
def add(shape)
raise NotImplementedError, "Cannot add #{shape.inspect} to #{type}"
end
|
#complex? ⇒ Boolean
49
|
# File 'lib/seahorse/type.rb', line 49
def complex?; false end
|
#default_type ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/seahorse/type.rb', line 39
def default_type
klass = self.class
last_klass = nil
while klass != Type
last_klass = klass
klass = klass.superclass
end
@default_type ||= last_klass.type
end
|
70
|
# File 'lib/seahorse/type.rb', line 70
def from_input(data, filter = true) data end
|
#inspect ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/seahorse/type.rb', line 26
def inspect
variables = instance_variables.map do |v|
next if v.to_s =~ /^@(?:(?:default_)?type|name|model)$/
[v.to_s[1..-1], instance_variable_get(v).inspect].join('=')
end.compact.join(' ')
variables = ' ' + variables if variables.length > 0
"#<Type(#{type})#{variables}>"
end
|
#pull_value(value) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/seahorse/type.rb', line 74
def pull_value(value)
found = false
names = as ? as : name
if names
names = [names].flatten
names.each do |name|
if value.respond_to?(name)
value = value.send(name)
found = true
elsif Hash === value
if value.has_key?(name)
value = value[name]
found = true
end
else
raise ArgumentError, "no property `#{name}' while looking for " +
"`#{names.join('.')}' on #{value.inspect}"
end
end
end
found ? value : nil
end
|
#to_hash ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/seahorse/type.rb', line 55
def to_hash
hash = {'type' => default_type}
hash['required'] = true if required
hash['location'] = location if location
hash['location'] = 'uri' if uri
if
= == true ? name :
hash['location'] = 'header'
hash['location_name'] =
hash['name'] =
end
hash['documentation'] = documentation if documentation
hash
end
|
#to_output(data) ⇒ Object
71
|
# File 'lib/seahorse/type.rb', line 71
def to_output(data) pull_value(data).to_s end
|
#to_strong_params ⇒ Object
72
|
# File 'lib/seahorse/type.rb', line 72
def to_strong_params; name.to_s end
|
#type ⇒ Object
35
36
37
|
# File 'lib/seahorse/type.rb', line 35
def type
@type ||= self.class.type.to_s
end
|