-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into v1.0.0-upgrading-guide
- Loading branch information
Showing
10 changed files
with
150 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule Membrane.Core.Inspect do | ||
@moduledoc false | ||
|
||
alias Inspect.Algebra | ||
alias Membrane.Core.Component | ||
|
||
@doc """ | ||
A function, that inspects passed state sorting its fields withing the order in which | ||
they occur in the list passed to `defstruct`. | ||
""" | ||
@spec inspect(Component.state(), Inspect.Opts.t()) :: Inspect.Algebra.t() | ||
def inspect(%state_module{} = state, opts) do | ||
ordered_fields = | ||
state_module.__info__(:struct) | ||
|> Enum.map(& &1.field) | ||
|
||
field_to_doc_fun = | ||
fn field, opts -> | ||
value_doc = | ||
Map.fetch!(state, field) | ||
|> Algebra.to_doc(opts) | ||
|
||
Algebra.concat("#{Atom.to_string(field)}: ", value_doc) | ||
end | ||
|
||
Algebra.container_doc( | ||
"%#{Kernel.inspect(state_module)}{", | ||
ordered_fields, | ||
"}", | ||
opts, | ||
field_to_doc_fun, | ||
break: :strict | ||
) | ||
end | ||
end | ||
|
||
[Pipeline, Bin, Element] | ||
|> Enum.map(fn component -> | ||
state_module = Module.concat([Membrane.Core, component, State]) | ||
|
||
defimpl Inspect, for: state_module do | ||
@spec inspect(unquote(state_module).t(), Inspect.Opts.t()) :: Inspect.Algebra.t() | ||
defdelegate inspect(state, opts), to: Membrane.Core.Inspect | ||
end | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters