ecto_state_machine icon indicating copy to clipboard operation
ecto_state_machine copied to clipboard

Introducing `is_column_state?` Functions

Open h4cc opened this issue 8 years ago • 3 comments

It would be cool, to have a praedicate to check if a column is in a state, like: is_update_successfull?

Code to use here:

      states
      |> Enum.each(fn(state) ->
        def unquote(:"is_#{column}_#{state}?")(model) do
          :"#{Map.get(model, unquote(column))}" == unquote(state)
        end
      end)

h4cc avatar Nov 28 '16 13:11 h4cc

@h4cc is there any way to avoid the meta-programming? Instead of use like is_#{column}_#{state}? create a function that receive a state and column and checks it?

I wouldn't push for this practices when we can avoid it.

yordis avatar Mar 18 '17 08:03 yordis

Nevermind, the whole implementation is based on this 😄

yordis avatar Mar 18 '17 08:03 yordis

@yordis if you know better way to implement this functionality, feel free to make a PR, or open an issue

asiniy avatar Mar 18 '17 10:03 asiniy