zendesk/biz

Store configuration in a database

23tux opened this issue · 4 comments

23tux commented

Hi,

is it possible to store the configuration somewhere as JSON or serialized ruby, and then apply this configuration in a new schedule?

I'm in the situation where I have multiple business hours for multiple shops and they should be able to edit them.

If this is not currently implemented, can you give me a hint how to do it? I would be happy to do a PR.

thanks!

Hey, @23tux!

Yes, there are all kinds of ways to store biz configurations. It really depends on which features of the gem you use.

Could you be more specific about what you're having trouble with?

23tux commented

Hi,

I try to access the configured hours from a Schedule. For now I have sub class that can does this

class OpeningHours < Biz::Schedule
  def raw
    configuration.send(:raw)
  end
end

I can then use opening_hours.raw.hours to access the configured hours.

I want to display them as a form and let the user store the hours inside the DB. Later this configuration is read and passed to config.hours (this works).

My fear when using private methods is always that they can change without any notes (therefore they're private), and I can't rely on them.

biz is agnostic to how you store configuration as long as you initialize a schedule through the public API. I would avoid subclassing any of biz's classes directly and keep user configuration separate and distinct from use of the gem.

You should validate, clean, and standardize any input before it ever reaches biz. It sounds like you're on the right track with creating a form to receive user input, but like I said, do this as a distinct step from biz. biz is focused solely on performing calculations and doesn't have anything to do with where that configuration comes from or how it's stored besides specifying the valid form in which to force user input.

23tux commented

Thanks for your answer! I'll try to find a way to separate them