Module: X::Resources::ValueMarshalling
- Included in:
- MatchingRule, PersonalizedTrend, PostUsage, Trend
- Defined in:
- x-resources/lib/x/resources/value_marshalling.rb
Overview
The state Marshal writes and reads of what an API response held that is not a resource
A trend, the usage of a project, and a rule a post matched hold their attributes alone, so what is written is those attributes, led by the number of their format, as a resource is written, and what is read is built of them as the constructor builds it, frozen.
Internal to x-resources: the methods it gives X::Trend, X::PersonalizedTrend, X::PostUsage, and X::MatchingRule, marshal_dump, marshal_load, encode_with, and init_with, are public API, but the module is only how they are shared, and which classes include it can change within 1.x.
Instance Method Summary collapse
-
#encode_with(coder) ⇒ void
Write the state Marshal writes as YAML.
-
#init_with(coder) ⇒ void
Restore a value YAML read, frozen, as Marshal restores one.
-
#marshal_dump ⇒ Array(Integer, Hash{String => Object})
The state Marshal writes.
-
#marshal_load(state) ⇒ void
Restore a value Marshal read, frozen as the value that was written was.
Instance Method Details
#encode_with(coder) ⇒ void
This method returns an undefined value.
Write the state Marshal writes as YAML
YAML would write the instance variables of the value, and read them back into one that is not frozen, so it says how it is written: each part of the state Marshal writes, under its name.
67 |
# File 'x-resources/lib/x/resources/value_marshalling.rb', line 67 def encode_with(coder) = YAML_KEYS.zip(marshal_dump) { |key, value| coder[key] = value } |
#init_with(coder) ⇒ void
This method returns an undefined value.
Restore a value YAML read, frozen, as Marshal restores one
77 |
# File 'x-resources/lib/x/resources/value_marshalling.rb', line 77 def init_with(coder) = marshal_load(coder.map.values_at(*YAML_KEYS)) |
#marshal_dump ⇒ Array(Integer, Hash{String => Object})
The state Marshal writes
What is written is plain data, led by the number of its format, so that a value written by one release of 1.x is read by a later one: its attributes, as the API sent them.
40 |
# File 'x-resources/lib/x/resources/value_marshalling.rb', line 40 def marshal_dump = [MARSHAL_FORMAT, attrs] |
#marshal_load(state) ⇒ void
This method returns an undefined value.
Restore a value Marshal read, frozen as the value that was written was
50 51 52 53 54 55 |
# File 'x-resources/lib/x/resources/value_marshalling.rb', line 50 def marshal_load(state) format, attrs = state raise UnsupportedFormat, "#{self.class} reads format #{MARSHAL_FORMAT} of Marshal, not #{format.inspect}" unless MARSHAL_FORMAT.eql?(format) restore(attrs) end |