lib/coco/options/group.rb in coveragebook_components-0.5.6 vs lib/coco/options/group.rb in coveragebook_components-0.5.7
- old
+ new
@@ -128,21 +128,12 @@
values.push(*item.flattened_attribute_values(key).to_a)
end
end.to_h
end
- def to_h
- {
- name: name,
- alias: @alias,
- shorthand: shorthand,
- options: items.map(&:to_h)
- }
- end
-
def clone
- Group.from_h(to_h)
+ Marshal.load(Marshal.dump(self))
end
protected
# All options in this group.
@@ -153,33 +144,9 @@
# All groups in this group
# Does not include groups in subgroups.
def groups
items.filter { _1.is_a?(Group) }
- end
-
- class << self
- # Recursively create an options tree from a hash.
- #
- # {
- # name: :root,
- # options: [
- # { name: :size, default: "md" },
- # { name: :dropdown, options: [{name: :placement, from: [:left, :right]}] }
- # }
- # }
- def from_h(data)
- group = Group.new(data.fetch(:name), **data.except(:options, :name))
- data.fetch(:options, []).each do |option|
- if option.key?(:options)
- subgroup = Group.from_h(option)
- group.add_group(subgroup)
- else
- group.add_option(option.fetch(:name), **option.except(:name))
- end
- end
- group
- end
end
end
end
end