Class: Sheetah::Types::Container
- Inherits:
-
Object
- Object
- Sheetah::Types::Container
- Defined in:
- lib/sheetah/types/container.rb
Constant Summary collapse
- DEFAULTS =
{ scalars: { scalar: -> { scalar }, string: -> { string }, email: -> { email }, boolsy: -> { boolsy }, date_string: -> { date_string }, }.freeze, composites: { array: ->(types) { Composites::Array.new!(types) }, array_compact: ->(types) { Composites::ArrayCompact.new!(types) }, }.freeze, }.freeze
Instance Method Summary collapse
- #composite(composite_name, scalar_names) ⇒ Object
- #composites ⇒ Object
-
#initialize(scalars: nil, composites: nil, defaults: DEFAULTS) ⇒ Container
constructor
A new instance of Container.
- #scalar(scalar_name) ⇒ Object
- #scalars ⇒ Object
Constructor Details
#initialize(scalars: nil, composites: nil, defaults: DEFAULTS) ⇒ Container
Returns a new instance of Container.
36 37 38 39 40 41 42 |
# File 'lib/sheetah/types/container.rb', line 36 def initialize(scalars: nil, composites: nil, defaults: DEFAULTS) @scalars = (scalars ? defaults[:scalars].merge(scalars) : defaults[:scalars]).freeze @composites = (composites ? defaults[:composites].merge(composites) : defaults[:composites]).freeze end |
Instance Method Details
#composite(composite_name, scalar_names) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/sheetah/types/container.rb', line 58 def composite(composite_name, scalar_names) builder = fetch_composite_builder(composite_name) scalars = scalar_names.map { |scalar_name| scalar(scalar_name) } builder.call(scalars) end |
#composites ⇒ Object
48 49 50 |
# File 'lib/sheetah/types/container.rb', line 48 def composites @composites.keys end |
#scalar(scalar_name) ⇒ Object
52 53 54 55 56 |
# File 'lib/sheetah/types/container.rb', line 52 def scalar(scalar_name) builder = fetch_scalar_builder(scalar_name) builder.call end |
#scalars ⇒ Object
44 45 46 |
# File 'lib/sheetah/types/container.rb', line 44 def scalars @scalars.keys end |