Class: MVCLI::Form::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/mvcli/form/input.rb

Defined Under Namespace

Classes: ListTarget, Target

Instance Method Summary collapse

Constructor Details

#initialize(name, target, options = {}, &block) ⇒ Input

Returns a new instance of Input.



5
6
7
8
# File 'lib/mvcli/form/input.rb', line 5

def initialize(name, target, options = {}, &block)
  @decoders = []
  @handler = handler(target).new name, target, options, &block
end

Instance Method Details

#decode(&block) ⇒ Object



10
11
12
# File 'lib/mvcli/form/input.rb', line 10

def decode(&block)
  @handler.decode &block
end

#handler(target) ⇒ Object



19
20
21
# File 'lib/mvcli/form/input.rb', line 19

def handler(target)
  target.is_a?(Array) ? ListTarget : Target
end

#value(source, context = nil, &transform) ⇒ Object



14
15
16
17
# File 'lib/mvcli/form/input.rb', line 14

def value(source, context = nil, &transform)
  transform ||= ->(v) { v }
  @handler.value source, context, &transform
end