Skip to content

Builder objects#8

Merged
parrish merged 2 commits intomasterfrom
builder_objects
Mar 16, 2018
Merged

Builder objects#8
parrish merged 2 commits intomasterfrom
builder_objects

Conversation

@parrish
Copy link
Owner

@parrish parrish commented Mar 2, 2018

Allows schemas to be built iteratively for #4:

obj = object
obj.string :name

Also allows schema entities to reopen and modify children with extend(name):

obj = object do
  object :an_object do
    string :name
  end
end

obj.extend(:an_object) do
  string :another_name
end

# an_object is now {properties: {name: {type: "string"}, another_name: {type: "string"}}}

To replace a child entity, just redefine it:

obj = object do
  object :an_object do
    string :name
  end
end

obj.object :an_object do
  string :replacement_name
end

# an_object is now only {properties: {replacement_name: {type: "string"}}}

@parrish parrish mentioned this pull request Mar 2, 2018
end

def extend(child_name, &block)
child = children.find { |c| c.name == child_name.to_sym }
Copy link

Choose a reason for hiding this comment

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

@parrish I think it would be useful to extract this into its own method.

object_with_child.child(:type) #=> ObjectBuilder<:type> 

Not sure about the name yet, but this way you could pass children easily to other functions as well.

Copy link

Choose a reason for hiding this comment

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

Maybe it would be enough to just return the child from extend if !block_given?

@Haniyya
Copy link

Haniyya commented Mar 2, 2018

Otherwise this looks really good. And it's nice that the actual changes are so small. 👍

parrish added 2 commits March 16, 2018 09:23
This triggers schema reinitialization when entities are added after
initialization.  Towards #4.
@parrish parrish merged commit 90e16e4 into master Mar 16, 2018
@parrish
Copy link
Owner Author

parrish commented Mar 16, 2018

@Haniyya extend also returns the child now. Released in v0.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants