Class: PencilPusher::Form
- Inherits:
-
Object
- Object
- PencilPusher::Form
- Includes:
- ActiveModel::Validations, ActiveModel::Validations::Callbacks
- Defined in:
- lib/pencil_pusher/form.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #cleaned_data ⇒ Object
- #error_messages ⇒ Object
-
#initialize(data) ⇒ Form
constructor
A new instance of Form.
- #recognized_data ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ Form
Returns a new instance of Form.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pencil_pusher/form.rb', line 16 def initialize(data) super(data) if data.nil? @validated = true @bound = false @data = {} else @validated = false @bound = true @data = data end errors.clear end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/pencil_pusher/form.rb', line 10 def data @data end |
Class Method Details
.attribute_names ⇒ Object
12 13 14 |
# File 'lib/pencil_pusher/form.rb', line 12 def self.attribute_names attribute_set.to_a.map(&:name) end |
Instance Method Details
#cleaned_data ⇒ Object
46 47 48 |
# File 'lib/pencil_pusher/form.rb', line 46 def cleaned_data attributes.reject { |key, value| value.nil? } end |
#error_messages ⇒ Object
42 43 44 |
# File 'lib/pencil_pusher/form.rb', line 42 def @_error_messages ||= errors. end |
#recognized_data ⇒ Object
50 51 52 |
# File 'lib/pencil_pusher/form.rb', line 50 def recognized_data data.slice(*attributes.keys) end |
#valid? ⇒ Boolean
32 33 34 35 36 37 38 39 40 |
# File 'lib/pencil_pusher/form.rb', line 32 def valid? @_valid ||= ( if bound? super else true end ) end |