Module: NitroRails::BroadcastableRecord
Instance Method Summary
collapse
#append_to_affiliated_lists, #broadcast_attribute, #broadcast_to_user_later, #broadcast_to_user_or_public_later, #focus_on_new_resource, #insert_into_affiliated_lists, #nitro_data_id, #partial_path, #redirect_to_index, #refresh_affiliatied_lists, #refresh_page, #remove_everywhere, #replace_attribute_content, #toggle_checkbox, #toggle_resource_attribute_class, #update_associated_attributes
Instance Method Details
#affiliation_keys ⇒ Object
67
68
69
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 67
def affiliation_keys
self.class.broadcast_affiliations
end
|
#affiliations ⇒ Object
71
72
73
74
75
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 71
def affiliations
affiliation_keys.map do |key|
send(key)
end.concat(belongs_to)
end
|
#attribute_broadcasts ⇒ Object
29
30
31
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 29
def attribute_broadcasts
self.class.attribute_broadcasts
end
|
#attribute_effects(attribute) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 47
def attribute_effects(attribute)
effects = ["replace_text", "replace_value", "replace_html"]
if status_attribute?(attribute)
if send(attribute).is_a?(TrueClass) || send(attribute).is_a?(FalseClass)
effects << "toggle_boolean_status_class"
else
effects << "update_status_class"
end
end
return effects
end
|
#attribute_effects_string(attribute) ⇒ Object
60
61
62
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 60
def attribute_effects_string(attribute)
attribute_effects(attribute).join(" ").camelize(:lower)
end
|
#belongs_to ⇒ Object
113
114
115
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 113
def belongs_to
self.class.reflect_on_all_associations(:belongs_to).map(&:name)
end
|
#broadcast(action) ⇒ Object
20
21
22
23
24
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 20
def broadcast(action)
self.class.action_broadcasts[action].to_a.each do |broadcast|
send(broadcast)
end
end
|
#broadcast_create ⇒ Object
8
9
10
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 8
def broadcast_create
broadcast(:create)
end
|
#broadcast_delete ⇒ Object
16
17
18
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 16
def broadcast_delete
broadcast(:delete)
end
|
#broadcast_update ⇒ Object
12
13
14
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 12
def broadcast_update
broadcast(:update)
end
|
#collection_tag ⇒ Object
93
94
95
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 93
def collection_tag
type.pluralize
end
|
#nitro_id(*attributes) ⇒ Object
105
106
107
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 105
def nitro_id(*attributes)
[resource_id.dasherize, *attributes.compact].join(':')
end
|
#path_for_record ⇒ Object
109
110
111
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 109
def path_for_record
send("#{type}_path", self)
end
|
#resource_id ⇒ Object
97
98
99
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 97
def resource_id
persisted? ? "#{type}_#{id}" : "#{type}_$#{temporary_id}"
end
|
#skipped_attributes ⇒ Object
33
34
35
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 33
def skipped_attributes
self.class.skipped_attributes
end
|
#status_attribute?(attribute) ⇒ Boolean
43
44
45
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 43
def status_attribute?(attribute)
status_attributes.include?(attribute)
end
|
#status_attributes ⇒ Object
39
40
41
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 39
def status_attributes
self.class.status_attributes
end
|
#template ⇒ Object
80
81
82
83
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 80
def template
@template ||= true
return self
end
|
#template? ⇒ Boolean
85
86
87
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 85
def template?
@template
end
|
#temporary_id ⇒ Object
101
102
103
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 101
def temporary_id
template? ? "template" : object_id
end
|
#type ⇒ Object
89
90
91
|
# File 'app/models/nitro_rails/broadcastable_record.rb', line 89
def type
self.class.name.underscore
end
|