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

Allow callable defaults? #136

Closed
tfausak opened this issue Feb 11, 2014 · 4 comments
Closed

Allow callable defaults? #136

tfausak opened this issue Feb 11, 2014 · 4 comments
Assignees
Labels
Milestone

Comments

@tfausak
Copy link
Collaborator

tfausak commented Feb 11, 2014

Should we allow callable defaults? That way you could determine the default value at "run" time instead of "compile" time.

class Interaction < ActiveInteraction::Base
  time :the_time,
       default: Time.now
  def execute
    Time.now - the_time
  end
end
Interaction.run!
# => 0.000992851
Interaction.run!
# => 0.001622327

I'm imagining something like this:

class Interaction < ActiveInteraction::Base
  time :the_time,
       default: -> { Time.now }
end
@AaronLasseigne
Copy link
Owner

I was thinking about this exact thing the other day. This strikes me as a reasonable approach.

@tfausak
Copy link
Collaborator Author

tfausak commented Feb 11, 2014

Oh yeah, I forgot my rationale. This sucks:

class Interaction < ActiveInteraction::Base
  time :the_time,
       default: nil
  def execute
    self.time = Time.now unless time?
  end
end

@tfausak tfausak added this to the v1.1.0 milestone Feb 18, 2014
@tfausak
Copy link
Collaborator Author

tfausak commented Feb 18, 2014

If we ever introduce a lambda filter, we're going to hate ourselves for this.

class Interaction < ActiveInteraction::Base
  function :a_lambda,
           default: -> { -> { 'oh god why' } }
end

@AaronLasseigne
Copy link
Owner

😆

tfausak added a commit that referenced this issue Feb 18, 2014
@tfausak tfausak self-assigned this Feb 18, 2014
@tfausak tfausak closed this as completed Feb 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants