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

Allowing aliases for :expects attributes on a LightService::Context object #67

Closed
rewinfrey opened this Issue Jun 18, 2015 · 4 comments

Comments

Projects
None yet
3 participants
@rewinfrey
Copy link

rewinfrey commented Jun 18, 2015

Let's say we have a generic action that expects a user to be supplied in the context.

Later, we create a new Organizer and for the context of that Organizer and its associated Actions, instead of user we care about the idea of an owner.

However, I want to use the generic action that expects the context to have an user. Currently, this causes me to have to create a small, specific action to convert the idea of an owner to an user:

class ExampleAction
  expects :owner
  promises :user

  executed do |context|
    context.user = context.owner
  end
end

This can quickly get out of hand though. Alternatively, at the time I create the owner object, I could associate it with an user at the same time:

class ExampleAction2
  expects :params
  promises :owner, :user

  executed do |context|
    context.user = context.owner = User.new(context.params)
  end
end

The trouble I have here is that our use of an action in this Organizer requiring an user leaks into an action that is really focused on the idea of an owner, which means that a more generic action meant to be reused is now leaking into other actions in order to be reused.

I'd like to propose we add the idea of expects aliases to LightService:

class ExampleAction3
  expects :user
  alias_context :user, :owner

  executed do |context|
    context.user.behavior!

    # which is equivalent to saying:
    # context.owner.behavior!
  end
end

What I hope ExampleAction3 demonstrates is how LightService can alias an object in the context
with another object in the context, and correctly send messages to the aliased object in the context when the aliased object exists. If there is no aliased object in the context, then expects and the context validation works as normal.

@adomokos

This comment has been minimized.

Copy link
Owner

adomokos commented Jun 18, 2015

👍 for this feature!

@jpmoral

This comment has been minimized.

Copy link
Contributor

jpmoral commented Jun 26, 2015

In my opinion, having the alias in ExampleAction3 also leaks information that somewhere, some other action passes an owner instead of a user. It seems that ExampleAction3 shouldn't have to know about the other possible names of what it expects.

What do you think of putting such functionality in the organizer? If we think of actions as self-contained parts, it seems that the organizer should be responsible for making the parts fit together.

@jpmoral

This comment has been minimized.

Copy link
Contributor

jpmoral commented Jul 4, 2015

@rewinfrey @adomokos
Please see my pull request: #68

@adomokos

This comment has been minimized.

Copy link
Owner

adomokos commented Jul 8, 2015

Thanks @jpmoral! Closing this Issue.

@adomokos adomokos closed this Jul 8, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.