Class: Uinit::Structure::AttributeBuilder
- Inherits:
-
Object
- Object
- Uinit::Structure::AttributeBuilder
- Defined in:
- lib/uinit/structure/attribute_builder.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#defaults ⇒ Object
Returns the value of attribute defaults.
Instance Method Summary collapse
- #abstract(type = nil, default = Attribute::UNDEFINED) ⇒ Object
- #alias(*aliases) ⇒ Object
- #array_struct(val = nil, &val_proc) ⇒ Object
- #as_json(val = nil, &val_proc) ⇒ Object
- #attr(name, type = nil, default = Attribute::UNDEFINED) ⇒ Object
- #default(val = nil, &val_proc) ⇒ Object
- #get(val = nil, &val_proc) ⇒ Object
- #init(val) ⇒ Object
-
#initialize(defaults, attribute = nil) ⇒ AttributeBuilder
constructor
A new instance of AttributeBuilder.
- #name(val) ⇒ Object
- #optional(val = true) ⇒ Object
- #private(*get_set) ⇒ Object
- #required ⇒ Object
- #set(val = nil, &val_proc) ⇒ Object
- #struct(val = nil, &val_proc) ⇒ Object
- #type(val) ⇒ Object
Constructor Details
#initialize(defaults, attribute = nil) ⇒ AttributeBuilder
Returns a new instance of AttributeBuilder.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/uinit/structure/attribute_builder.rb', line 6 def initialize(defaults, attribute = nil) self.attribute = attribute || Attribute.new self.defaults = defaults return if attribute defaults.each do |(name, value)| self.attribute.send(:"#{name}=", value) end end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
17 18 19 |
# File 'lib/uinit/structure/attribute_builder.rb', line 17 def attribute @attribute end |
#defaults ⇒ Object
Returns the value of attribute defaults.
17 18 19 |
# File 'lib/uinit/structure/attribute_builder.rb', line 17 def defaults @defaults end |
Instance Method Details
#abstract(type = nil, default = Attribute::UNDEFINED) ⇒ Object
27 28 29 |
# File 'lib/uinit/structure/attribute_builder.rb', line 27 def abstract(type = nil, default = Attribute::UNDEFINED, &) build(type, default, &) end |
#alias(*aliases) ⇒ Object
109 110 111 112 113 |
# File 'lib/uinit/structure/attribute_builder.rb', line 109 def alias(*aliases) attribute.aliases = aliases self end |
#array_struct(val = nil, &val_proc) ⇒ Object
61 62 63 64 65 |
# File 'lib/uinit/structure/attribute_builder.rb', line 61 def array_struct(val = nil, &val_proc) attribute.array_struct = val.nil? ? val_proc : val self end |
#as_json(val = nil, &val_proc) ⇒ Object
103 104 105 106 107 |
# File 'lib/uinit/structure/attribute_builder.rb', line 103 def as_json(val = nil, &val_proc) attribute.as_json = val.nil? ? val_proc : val self end |
#attr(name, type = nil, default = Attribute::UNDEFINED) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/uinit/structure/attribute_builder.rb', line 19 def attr(name, type = nil, default = Attribute::UNDEFINED, &) return build_mutliple(name, type, default, &) if name.is_a?(Array) self.name(name) build(type, default, &) end |
#default(val = nil, &val_proc) ⇒ Object
67 68 69 70 71 |
# File 'lib/uinit/structure/attribute_builder.rb', line 67 def default(val = nil, &val_proc) attribute.default = val.nil? ? val_proc : val self end |
#get(val = nil, &val_proc) ⇒ Object
91 92 93 94 95 |
# File 'lib/uinit/structure/attribute_builder.rb', line 91 def get(val = nil, &val_proc) attribute.get = val.nil? ? val_proc : val self end |
#init(val) ⇒ Object
85 86 87 88 89 |
# File 'lib/uinit/structure/attribute_builder.rb', line 85 def init(val) attribute.init = val self end |
#name(val) ⇒ Object
43 44 45 46 47 |
# File 'lib/uinit/structure/attribute_builder.rb', line 43 def name(val) attribute.name = val self end |
#optional(val = true) ⇒ Object
73 74 75 76 77 |
# File 'lib/uinit/structure/attribute_builder.rb', line 73 def optional(val = true) attribute.optional = val self end |
#private(*get_set) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/uinit/structure/attribute_builder.rb', line 31 def private(*get_set) if get_set.empty? attribute.private_get = true attribute.private_set = true else attribute.private_get = true if get_set.include?(:get) attribute.private_set = true if get_set.include?(:set) end self end |
#required ⇒ Object
79 80 81 82 83 |
# File 'lib/uinit/structure/attribute_builder.rb', line 79 def required attribute.optional = false self end |
#set(val = nil, &val_proc) ⇒ Object
97 98 99 100 101 |
# File 'lib/uinit/structure/attribute_builder.rb', line 97 def set(val = nil, &val_proc) attribute.set = val.nil? ? val_proc : val self end |
#struct(val = nil, &val_proc) ⇒ Object
55 56 57 58 59 |
# File 'lib/uinit/structure/attribute_builder.rb', line 55 def struct(val = nil, &val_proc) attribute.struct = val.nil? ? val_proc : val self end |
#type(val) ⇒ Object
49 50 51 52 53 |
# File 'lib/uinit/structure/attribute_builder.rb', line 49 def type(val) attribute.type = val self end |