Skip to content

Commit

Permalink
Basic hooks for Plumb::Attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ismasan committed Aug 26, 2024
1 parent f7b20b4 commit ee0c352
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/plumb/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ def attribute(name, type = Types::Any, &block)
name = key.to_sym
type = Composable.wrap(type)
if block_given? # :foo, Array[Data] or :foo, Struct
type = Types::Data if type == Types::Any
type = __plumb_struct_class__ if type == Types::Any
type = Plumb.decorate(type) do |node|
if node.is_a?(Plumb::ArrayClass)
child = node.children.first
child = Types::Data if child == Types::Any
child = __plumb_struct_class__ if child == Types::Any
Types::Array[build_nested(name, child, &block)]
elsif node.is_a?(Plumb::Step)
build_nested(name, node, &block)
Expand All @@ -228,6 +228,12 @@ def attribute(name, type = Types::Any, &block)
end

@_schema = _schema + { key => type }
__plumb_define_attribute_method__(name)
end

def __plumb_struct_class__ = Types::Data

def __plumb_define_attribute_method__(name)
define_method(name) { @attributes[name] }
end

Expand Down

0 comments on commit ee0c352

Please sign in to comment.