Module: Server::Helpers
Instance Method Summary
collapse
#nav_class, #render_partial, #render_scope, #scope_help, #scope_info, #scope_initials, #scope_meta_info, #scope_title
Instance Method Details
69
70
71
|
# File 'lib/server.rb', line 69
def changed
"<h3>In both with different attributes:</h3>"
end
|
#changed_elements(scope, opts) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/server.rb', line 82
def changed_elements(scope, opts)
optional_attributes = opts[:optional_attributes] || []
changed = []
@diff[scope].changed.each do |change|
changes = []
relevant_attributes = if opts[:attributes]
opts[:attributes].dup
else
change[0].attributes.keys & change[1].attributes.keys
end
(1..optional_attributes.length).each do |i|
if change[0][optional_attributes[i - 1]] ==
change[1][optional_attributes[i - 1]]
relevant_attributes.push(optional_attributes[i])
else
break
end
end
relevant_attributes.each do |attribute|
if change[0][attribute] != change[1][attribute]
changes.push(
attribute + ": " + human_readable_attribute(change[0], attribute) + " ↔ " +
human_readable_attribute(change[1], attribute)
)
end
end
changed.push(
id: change[0][opts[:key]],
change: "(" + changes.join(", ") + ")",
diffable: change[0].is_a?(Machinery::UnmanagedFile) &&
change[0].is_a?(Machinery::UnmanagedFile) &&
change[0].file? && change[1].file? &&
@diff[scope].try(:common).try(:attributes).try(:[], "extracted")
)
end
changed
end
|
#human_readable_attribute(object, attribute) ⇒ Object
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/server.rb', line 123
def human_readable_attribute(object, attribute)
value = object[attribute]
case object
when Machinery::SystemFile
value = number_to_human_size(value) if attribute == "size"
end
value.to_s
end
|
60
61
62
|
# File 'lib/server.rb', line 60
def in_both
"<h3>In both descriptions:</h3>"
end
|
#offset_class(first_col) ⇒ Object
64
65
66
67
|
# File 'lib/server.rb', line 64
def offset_class(first_col)
return "" if first_col
"col-md-offset-6"
end
|
#only_in_a ⇒ Object
52
53
54
|
# File 'lib/server.rb', line 52
def only_in_a
"<h3>Only in '#{@description_a.name}':</h3>"
end
|
#only_in_b ⇒ Object
56
57
58
|
# File 'lib/server.rb', line 56
def only_in_b
"<h3>Only in '#{@description_b.name}':</h3>"
end
|
#pluralize_scope(object, singular, plural) ⇒ Object
73
74
75
|
# File 'lib/server.rb', line 73
def pluralize_scope(object, singular, plural)
object.length.to_s + " " + Machinery.pluralize(object.length, singular, plural)
end
|
#repository_changes ⇒ Object
77
78
79
80
|
# File 'lib/server.rb', line 77
def repository_changes
klass = @diff["repositories"].changed.first.first.class
changed_elements("repositories", attributes: klass.attributes, key: klass.key)
end
|
#safe_length(object, attribute) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/server.rb', line 44
def safe_length(object, attribute)
if collection = object.try(attribute)
collection.length
else
0
end
end
|