-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define status as struct #3
Conversation
- Define struct Status - Return list of status directly from Statuses module instead of reading a json file - add a function to return statuses as json
Update Readme and mix.exs config file for package
Codecov Report
@@ Coverage Diff @@
## main #3 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 4 2 -2
=========================================
- Hits 4 2 -2
Continue to review full report at Codecov.
|
@@ -23,10 +23,6 @@ jobs: | |||
path: deps | |||
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} | |||
restore-keys: ${{ runner.os }}-mix- | |||
- name: Install Node.js Deps (JSON Lint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the PR doesn't have the json file, we don't need to install npm pacakage
""" | ||
@type t :: %Status{code: integer(), desc: String.t(), text: atom()} | ||
@enforce_keys [:code, :desc, :text] | ||
@derive Jason.Encoder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need to encode some struct that does not implement the protocol, if you own the struct, you can derive the implementation specifying which fields should be encoded to JSON
https://github.com/michalmuskala/jason#differences-to-poison
Define the Status struct with desc, id and text key required | ||
""" | ||
@type t :: %Status{code: integer(), desc: String.t(), text: atom()} | ||
@enforce_keys [:code, :desc, :text] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the keys are required
@doc """ | ||
Returns the list of statuses as json | ||
""" | ||
def statuses_to_json(), do: Jason.encode!(get_statuses()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a function to return json, I don't think we'll use it but I can see how it can be useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SimonLab looks good. 👍
Detailed response in the issue: #4 (comment)
Package published to https://hex.pm/packages/statuses/1.1.0 📦 🚀 |
use Struct to define the list of statuses, remove json file and
File.read
functionref: #4
@nelsonic let me know your thought on this,thanks