Skip to content
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

WIP Crutches.Option module #43

Merged
merged 4 commits into from
Aug 4, 2015
Merged

WIP Crutches.Option module #43

merged 4 commits into from
Aug 4, 2015

Conversation

duijf
Copy link
Collaborator

@duijf duijf commented Jul 26, 2015

Functions to turn this:

@function_name [
  valid_options: [:some, :option],
  default_options: [
    some: "foo"
    option: "bar"
  ]
]
def function_name(args, opts \\ @function_name[:default_options])
def function_name(args, opts) do
  Crutches.Keyword.validate_keys!(opts, @function_name[:valid_options])
  options = Keyword.merge(@function_name[:default_options], opts)

  ...
end

Into this:

@function_name [
  valid: [:some, :option],
  defaults: [
    some: "foo",
    option: "bar"
  ]
]
def function_name(args, opts \\ @function_name[:defaults])
def function_name(args, opts) do
  # This validates and merges the options, throwing on error.
  opts = Crutches.Options.combine!(opts, @function_name)

  ...
end

For more context, see #42.

Refactoring of the library to make use of these new functions is not going to happen in this PR, in order for everyone to be able to benefit from these functions as quickly as possible.

TODOs:

  • Option.combine!(options, configuration) — throwing
  • Option.combine(options, configuration) — non-throwing
  • Option.combine!(options, configuration, combinator) — throwing, with custom combinator.
  • Option.combine(options, configuration, combinator) — non-throwing, with custom combinator.
  • Move the functions from Crutches.Keyword into Crutches.Option

@duijf duijf changed the title WIP Crutches.Options module WIP Crutches.Option module Jul 26, 2015
@duijf
Copy link
Collaborator Author

duijf commented Jul 26, 2015

Hmm, weird that the build is failing. Might have to do with other warnings, but I doubt that'd make it segfault. Temporarily fixing all warnings (will drop from commit history if unsuccessful).

@duijf
Copy link
Collaborator Author

duijf commented Jul 26, 2015

That seems to have done it. If wanted, that commit could go somewhere else.

"""
@spec combine(list(any), list(any)) :: list(any)
def combine(opts, config) do
Crutches.Option.combine(opts, config, &Elixir.Keyword.merge(&1, &2))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call combine(args) instead of Crutches.Option.combine(args). Ditto for other occurrences.

P.S. Great work dude!

@duijf
Copy link
Collaborator Author

duijf commented Aug 4, 2015

@KNRZ Incorporated your feedback. Currently working on the last checkbox.

duijf added a commit that referenced this pull request Aug 4, 2015
Crutches.Option module

Functions to turn this:

```
@function_name [
  valid_options: [:some, :option],
  default_options: [
    some: "foo"
    option: "bar"
  ]
]
def function_name(args, opts \\ @function_name[:default_options])
def function_name(args, opts) do
  Crutches.Keyword.validate_keys!(opts, @function_name[:valid_options])
  options = Keyword.merge(@function_name[:default_options], opts)

  ...
end
```

Into this:

```
@function_name [
  valid: [:some, :option],
  defaults: [
    some: "foo",
    option: "bar"
  ]
]
def function_name(args, opts \\ @function_name[:defaults])
def function_name(args, opts) do
  # This validates and merges the options, throwing on error.
  opts = Crutches.Options.combine!(opts, @function_name)

  ...
end
```
@duijf duijf merged commit f3b8a99 into mykewould:master Aug 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants