Module: CaringForm::FieldContainer::ClassMethods
- Defined in:
- lib/caring_form/field_container.rb
Instance Method Summary collapse
Instance Method Details
#field(name, options = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/caring_form/field_container.rb', line 72 def field(name, = {}) if (not_supported = .keys - CaringForm::Field.field_attributes).present? raise Error.new("CaringForm::Dsl.field: #{not_supported.join(', ')} not supported") end supported_option_names = CaringForm::Field.field_attributes values = .values_at(*supported_option_names) if [:type] == :submit field = new_field(:submit, *values) field.properties = Array(name) name = :submit else field = new_field(name, *values) field.apply_to_model(self) end @fields[name.to_sym] = field end |
#field_names(&block) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/caring_form/field_container.rb', line 89 def field_names(&block) real_fields = fields.reject { |_, field| field.kind_of?(CaringForm::Field::Submit) } return real_fields.keys.map(&:to_s) unless block_given? selected = real_fields.select(&block) # ruby 1.8 returns an array, 1.9 returns a hash keys = selected.is_a?(Array) ? selected.map(&:first) : selected.keys keys.map(&:to_s) end |
#inherited(subclass) ⇒ Object
98 99 100 |
# File 'lib/caring_form/field_container.rb', line 98 def inherited(subclass) subclass.fields = self.fields.dup end |