Class: Pigeon::ChannelSchema
- Inherits:
-
Object
- Object
- Pigeon::ChannelSchema
show all
- Includes:
- NestedScopes
- Defined in:
- app/models/pigeon/channel_schema.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#find_attr_recursive, #find_attr_ref_recursive, #fold_scoped_name
Constructor Details
#initialize(type, kind, humanized_name = nil, attributes = [], template = nil) ⇒ ChannelSchema
Returns a new instance of ChannelSchema.
20
21
22
23
24
25
26
27
28
29
|
# File 'app/models/pigeon/channel_schema.rb', line 20
def initialize(type, kind, humanized_name = nil, attributes = [], template = nil)
raise ArgumentError, "type cannot be blank" if type.blank?
raise ArgumentError, "kind cannot be blank" if kind.blank?
@type = type
@kind = kind
@humanized_name = humanized_name || kind
@attribute_data = attributes
@template_data = template
end
|
Instance Attribute Details
#attribute_data ⇒ Object
Returns the value of attribute attribute_data.
18
19
20
|
# File 'app/models/pigeon/channel_schema.rb', line 18
def attribute_data
@attribute_data
end
|
#humanized_name ⇒ Object
Returns the value of attribute humanized_name.
18
19
20
|
# File 'app/models/pigeon/channel_schema.rb', line 18
def humanized_name
@humanized_name
end
|
#kind ⇒ Object
Returns the value of attribute kind.
18
19
20
|
# File 'app/models/pigeon/channel_schema.rb', line 18
def kind
@kind
end
|
#template_data ⇒ Object
Returns the value of attribute template_data.
18
19
20
|
# File 'app/models/pigeon/channel_schema.rb', line 18
def template_data
@template_data
end
|
#type ⇒ Object
Returns the value of attribute type.
18
19
20
|
# File 'app/models/pigeon/channel_schema.rb', line 18
def type
@type
end
|
Class Method Details
.from_hash(type, hash) ⇒ Object
6
7
8
|
# File 'app/models/pigeon/channel_schema.rb', line 6
def from_hash(type, hash)
self.new type, hash["kind"], hash["humanized_name"], hash["attributes"], hash["template"]
end
|
.list_from_hash(type, hash) ⇒ Object
10
11
12
13
14
15
|
# File 'app/models/pigeon/channel_schema.rb', line 10
def list_from_hash(type, hash)
hash.map do |name, data|
data["kind"] ||= name
from_hash type, data
end
end
|
Instance Method Details
#attributes ⇒ Object
31
32
33
|
# File 'app/models/pigeon/channel_schema.rb', line 31
def attributes
@attributes ||= process_attributes(@attribute_data)
end
|
#default_template ⇒ Object
57
58
59
60
61
|
# File 'app/models/pigeon/channel_schema.rb', line 57
def default_template
["@template"] + user_attributes.map do |attr_name|
["@attr", attr_name]
end
end
|
#default_values ⇒ Object
45
46
47
|
# File 'app/models/pigeon/channel_schema.rb', line 45
def default_values
recursive_map_filter(attributes, &:default_value)
end
|
#find_attribute(name) ⇒ Object
63
64
65
|
# File 'app/models/pigeon/channel_schema.rb', line 63
def find_attribute(name)
find_attr_recursive(name, attributes)
end
|
#known_attributes ⇒ Object
35
36
37
|
# File 'app/models/pigeon/channel_schema.rb', line 35
def known_attributes
attributes.keys
end
|
#template ⇒ Object
49
50
51
|
# File 'app/models/pigeon/channel_schema.rb', line 49
def template
@template ||= @template_data ? process_template(@template_data) : default_template
end
|
#type_kind ⇒ Object
53
54
55
|
# File 'app/models/pigeon/channel_schema.rb', line 53
def type_kind
"#{type}/#{kind}"
end
|
#user_attributes ⇒ Object
39
40
41
42
43
|
# File 'app/models/pigeon/channel_schema.rb', line 39
def user_attributes
flattened_map_filter(attributes) do |attr|
attr.user_editable ? attr.scoped_name : nil
end
end
|