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

add support for calculated_default attribute #70

Merged
merged 7 commits into from
Apr 17, 2015
Merged

add support for calculated_default attribute #70

merged 7 commits into from
Apr 17, 2015

Conversation

nnutter
Copy link
Contributor

@nnutter nnutter commented Apr 9, 2015

From the POD,

calculated_default is a name of an instance method or a code ref to be used to resolve a default value during object creation. The instance method will be called immediately after UR creates the initial entity so the method will have access to other parameters used during creation.

Specifying calculated_default => 1 is equivalent to,

calculated_default => '__default_' . $prop_name . '__'

and is meant to establish a naming convention without requiring it.

@nnutter nnutter changed the title add support for default_from (method) attribute prototyping support for default_from (method) attribute Apr 9, 2015
@@ -808,6 +815,13 @@ sub create_entity {
$params = { $rule->params_list }; ;
}

my %default_value_requires_call = %$initial_default_value_requires_call;
for my $name (keys %$initial_default_value_requires_call) {
if ($params->{$name}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be if (exists $params->{$name}) { to allow specifying a false-y value in create()

@brummett
Copy link
Contributor

brummett commented Apr 9, 2015

Needs some documentation in UR/Object/Type/Initializer.pod

@brummett
Copy link
Contributor

brummett commented Apr 9, 2015

default_from => 1 reads pretty poorly. I thought about lazy_default => 1. That reads better (and works for the other use cases), but "lazy" doesn't really describe what's going on.

@nnutter
Copy link
Contributor Author

nnutter commented Apr 9, 2015

default_from => 1 reads pretty poorly. I thought about lazy_default => 1. That reads better (and works for the other use cases), but "lazy" doesn't really describe what's going on.

Brainstorming...

  • dynamic_default => 1
  • default_at_construction => 1
  • default_at_create =>
  • calculated_default => 1

@nnutter
Copy link
Contributor Author

nnutter commented Apr 9, 2015

FYI, I implemented Genome::Configurable with this, genome/genome@9243b8b.

@nnutter
Copy link
Contributor Author

nnutter commented Apr 9, 2015

I pushed commits to address feedback so far (besides picking a better name than default_from).

@nnutter nnutter changed the title prototyping support for default_from (method) attribute add support for default_from (method) attribute Apr 10, 2015
@nnutter nnutter changed the title add support for default_from (method) attribute add support for default_from attribute Apr 10, 2015
@nnutter nnutter changed the title add support for default_from attribute add support for calculated_default attribute Apr 13, 2015
@nnutter
Copy link
Contributor Author

nnutter commented Apr 13, 2015

Pushed commits to rename default_from to calculated_default.

@brummett
Copy link
Contributor

+1 after tests pass

nnutter added a commit that referenced this pull request Apr 17, 2015
add support for calculated_default attribute
@nnutter nnutter merged commit d1536b9 into genome:master Apr 17, 2015
@nnutter nnutter deleted the default branch April 17, 2015 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants