-
Notifications
You must be signed in to change notification settings - Fork 86
Add ja_resource #332
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
Merged
Merged
Add ja_resource #332
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,10 @@ | ||
| defmodule CodeCorps.Analytics.InMemoryAPI do | ||
| @moduledoc """ | ||
| In-memory interface to simulate calling out to the Segment API. | ||
|
|
||
| Each function should have the same signature as `CodeCorps.Analytics.SegmentAPI` and simply return `nil`. | ||
| """ | ||
|
|
||
| def identify(_user_id, _traits), do: nil | ||
| def track(_user_id, _event_name, _properties), do: nil | ||
| end |
This file contains hidden or 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 hidden or 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,13 @@ | ||
| defmodule CodeCorps.Analytics.SegmentAPI do | ||
| @moduledoc """ | ||
| Interface to the Segment API through the [`analytics-elixir` package](https://github.com/stueccles/analytics-elixir). | ||
| """ | ||
|
|
||
| def identify(user_id, traits) do | ||
| Segment.Analytics.identify(user_id, traits) | ||
| end | ||
|
|
||
| def track(user_id, event_name, properties) do | ||
| Segment.Analytics.track(user_id, event_name, properties) | ||
| end | ||
| end |
This file contains hidden or 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,18 @@ | ||
| defmodule CodeCorps.Helpers.Query do | ||
| import CodeCorps.Helpers.String, only: [coalesce_id_string: 1, coalesce_string: 1] | ||
| import Ecto.Query, only: [where: 3] | ||
|
|
||
| def id_filter(query, id_list) do | ||
| ids = id_list |> coalesce_id_string | ||
| query |> where([object], object.id in ^ids) | ||
| end | ||
|
|
||
| def organization_filter(query, organization_id) do | ||
| query |> where([object], object.organization_id == ^organization_id) | ||
| end | ||
|
|
||
| def role_filter(query, roles_list) do | ||
| roles = roles_list |> coalesce_string | ||
| query |> where([object], object.role in ^roles) | ||
| end | ||
| end |
This file contains hidden or 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,15 @@ | ||
| defmodule CodeCorps.Helpers.Slug do | ||
| alias Ecto.Changeset | ||
|
|
||
| def generate_slug(changeset, value_key, slug_key) do | ||
| case changeset do | ||
| %Changeset{valid?: true, changes: changes} -> | ||
| case Map.fetch(changes, value_key) do | ||
| {:ok, value} -> Changeset.put_change(changeset, slug_key, Inflex.parameterize(value)) | ||
| _ -> changeset | ||
| end | ||
| _ -> | ||
| changeset | ||
| end | ||
| end | ||
| end |
2 changes: 1 addition & 1 deletion
2
web/controllers/controller_helpers.ex → lib/code_corps/helpers/string.ex
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there any way to pattern match on the
record's type at all for extra type safety?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.
Outside of having one function signature for every single record type, I'm not sure there is.