Class: TypedFormModel::PropMetadata

Inherits:
Data
  • Object
show all
Defined in:
lib/typed_form_model/prop_metadata.rb

Overview

Per-prop metadata captured at declaration time for options that Literal doesn't know about (model-mapping, transforms). Immutable value object. model and attribute are the parsed pieces of the DSL from: kwarg (a Symbol fills only attribute; a "src.attr" String fills both).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attribute ⇒ Object (readonly)

Returns the value of attribute attribute

Returns:

  • (Object) —

    the current value of attribute



8
9
10
# File 'lib/typed_form_model/prop_metadata.rb', line 8

def attribute
  @attribute
end

#model ⇒ Object (readonly)

Returns the value of attribute model

Returns:

  • (Object) —

    the current value of model



8
9
10
# File 'lib/typed_form_model/prop_metadata.rb', line 8

def model
  @model
end

#transform ⇒ Object (readonly)

Returns the value of attribute transform

Returns:

  • (Object) —

    the current value of transform



8
9
10
# File 'lib/typed_form_model/prop_metadata.rb', line 8

def transform
  @transform
end

Instance Method Details

#maps_to?(model_name) ⇒ Boolean

Is this prop mapped to the given source name (the first segment of a dotted from:)?

Returns:

  • (Boolean)


15
# File 'lib/typed_form_model/prop_metadata.rb', line 15

def maps_to?(model_name) = model == model_name

#model_attribute(prop_name) ⇒ Object

The target attribute name on the model; defaults to the prop name when from: did not specify a rename.



11
# File 'lib/typed_form_model/prop_metadata.rb', line 11

def model_attribute(prop_name) = attribute || prop_name