Hello there everyone,
I’ve been working on this pet project for a while now. It’s a very interesting idea, the concept is around a content sharing platform but instead of each person having a personalized feed that they can scroll through, the content exists in locations that can be explored by users.
Here is the repo to the project
One of the core concepts in this platform are actions that can be taken by users, right now to handle all the actions I define functions in a module I call Ruleset.Basic. This seems to work well for now however I can see this will get out of hand as I’m going to be defining more functionality, furthermore I envisioned this platform with extendible and composable rulesets, where one can define actions on separate modules (ideally using some macros to make them cleaner) and then one could put these actions into a ruleset module. By doing something like
defmodule SomeRuleset do
use Ruleset
register_actions [ActionModule1, ActionModule2, ActionModule3]
# Other ruleset functionality
end
I tried to work on the DSL to come up with how I would ideally like to define these actions and some expriments are here and here.
I would like to ask of the community if they could help me figure this out.
The requirements are:
- Defining actions is clean and effortless to do
- Actions defined can be included in different ruleset modules
- Undefined functionality defaults to doing nothing
One solution I came up with while writing this would be to use structs as a basis to define the functions in the end. That would require writing less macros and seems it could be quite extendible and flexible.
Something among the lines
%DefinedAction{
name: :some_action,
cost: 20,
on_action_taken: fn exlorer, action -> "updates on explorer on action taken" end,
valid_when: fn exlorer, action -> "validation before taking action" end,
reaction: %{
journey: [affect: :location]
},
affects: %{
exlorer: fn exlorer, action -> "updates on explorer on action passed" end,
location: fn location, action -> "updates on explorer on action passed"
}
And then this struct could be used to define the functions with much less fuzz than having several macros one for each key we have here.
Would the former make sense? Would it be a good solution to problem?
Thank you for taking the time to read, Is anyone with interest in helping me figure out an ellegant solution?
Also if anyone find the project a cool idea and want to help out in any way let me know. There is lots to do still and any help is appreciated!!