Class: Readymade::Form::FormOptions

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ FormOptions

Returns a new instance of FormOptions.



186
187
188
189
# File 'lib/readymade/form.rb', line 186

def initialize(**args)
  @args = args
  @f_class = args.delete(:form_class)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



184
185
186
# File 'lib/readymade/form.rb', line 184

def args
  @args
end

Instance Method Details

#[](key) ⇒ Object



191
192
193
# File 'lib/readymade/form.rb', line 191

def [](key)
  to_h[key]
end

#as_json(options = {}) ⇒ Object



201
202
203
# File 'lib/readymade/form.rb', line 201

def as_json(options = {})
  to_h.as_json(options)
end

#required?(attr) ⇒ Boolean

Returns:

  • (Boolean)


205
206
207
# File 'lib/readymade/form.rb', line 205

def required?(attr)
  @f_class::REQUIRED_ATTRIBUTES.include?(attr.to_sym)
end

#to_hObject

Raises:



195
196
197
198
199
# File 'lib/readymade/form.rb', line 195

def to_h
  raise Readymade::Error.new('define form_options on your form') unless (f = @f_class.new({}, **@args)).respond_to?(:form_options)

  f.form_options
end