Module: Ossert::Saveable
- Included in:
- Project
- Defined in:
- lib/ossert/saveable.rb
Defined Under Namespace
Modules: ClassMethods
Classes: RecordInvalid
Constant Summary
collapse
- UNUSED_REFERENCE =
'unused'
{
agility_total_data: ->(project) { project.agility.total.to_json },
agility_quarters_data: ->(project) { project.agility.quarters.to_json },
community_total_data: ->(project) { project..total.to_json },
community_quarters_data: ->(project) { project..quarters.to_json },
meta_data: ->(project) { project.meta_to_json }
}.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
13
14
15
|
# File 'lib/ossert/saveable.rb', line 13
def self.included(base)
base.extend(ClassMethods)
end
|
Instance Method Details
#attributes ⇒ Object
52
53
54
|
# File 'lib/ossert/saveable.rb', line 52
def attributes
meta_attributes.merge(data_attributes)
end
|
#data_attributes ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/ossert/saveable.rb', line 65
def data_attributes
{
meta_data: meta_to_json,
agility_total_data: agility.total.to_json,
agility_quarters_data: agility.quarters.to_json,
community_total_data: .total.to_json,
community_quarters_data: .quarters.to_json
}
end
|
#dump ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/ossert/saveable.rb', line 26
def dump
validate!
if (found_project = ::Project.find(name: name))
found_project.update(attributes.merge(updated_at: Time.now.utc))
else
::Project.create(attributes)
end
nil
end
|
#dump_attribute(attriibute) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/ossert/saveable.rb', line 17
def dump_attribute(attriibute)
attriibute = attriibute.to_sym
value = ATTRIBUTE_EXTRACT_VALUE_MAP.fetch(attriibute).call(self)
raise 'Not saved yet, sorry!' unless (found_project = ::Project.find(name: name))
found_project.update(name, attriibute => value, updated_at: Time.now.utc)
nil
end
|
56
57
58
59
60
61
62
63
|
# File 'lib/ossert/saveable.rb', line 56
def meta_attributes
{
name: name,
github_name: github_alias,
rubygems_name: rubygems_alias,
reference: reference
}
end
|
#valid? ⇒ Boolean
36
37
38
|
# File 'lib/ossert/saveable.rb', line 36
def valid?
[name, github_alias, rubygems_alias].all?(&:present?)
end
|
#validate! ⇒ Object
48
49
50
|
# File 'lib/ossert/saveable.rb', line 48
def validate!
raise RecordInvalid.new unless valid?
end
|
#without_github_data? ⇒ Boolean
75
76
77
|
# File 'lib/ossert/saveable.rb', line 75
def without_github_data?
github_alias == NO_GITHUB_NAME
end
|