class Domino::Form
Constants
- FIELD_TYPES
Public Class Methods
create(attributes = {})
click to toggle source
# File lib/domino/form.rb, line 55 def self.create(attributes = {}) find!.create(attributes) end
field(*args, &callback)
click to toggle source
# File lib/domino/form.rb, line 31 def self.field(*args, &callback) options = args.last.is_a?(::Hash) ? args.pop : {} attribute, locator = *args locator ||= !@key.to_s.empty? ? "#{@key}[#{attribute}]" : attribute field_type = options.delete(:as) field_class = field_type.is_a?(Class) && field_type.ancestors.include?(Field) ? field_type : FIELD_TYPES[field_type] || Field field_definitions[attribute] = field_class.new(attribute, locator, options, &callback) define_method :"#{attribute}" do |&block| if block.is_a?(Proc) block.call(self.class.field_definitions[attribute].field(node)) else self.class.field_definitions[attribute].value(node) end end define_method :"#{attribute}=" do |value| self.class.field_definitions[attribute].write(node, value) end end
field_definitions()
click to toggle source
# File lib/domino/form.rb, line 19 def self.field_definitions @field_definitions ||= {} end
fields()
click to toggle source
# File lib/domino/form.rb, line 15 def self.fields field_definitions.keys end
key(k)
click to toggle source
# File lib/domino/form.rb, line 11 def self.key(k) @key = k end
submit_with(submitter)
click to toggle source
# File lib/domino/form.rb, line 23 def self.submit_with(submitter) @submitter = submitter end
submitter()
click to toggle source
# File lib/domino/form.rb, line 27 def self.submitter @submitter ||= "input[type='submit']" end
update(attributes = {})
click to toggle source
# File lib/domino/form.rb, line 59 def self.update(attributes = {}) find!.update(attributes) end
Public Instance Methods
create(attributes = {})
click to toggle source
# File lib/domino/form.rb, line 63 def create(attributes = {}) set(attributes) save end
fields()
click to toggle source
# File lib/domino/form.rb, line 81 def fields self.class.fields.each_with_object({}) do |field, memo| memo[field] = send(field) end end
save()
click to toggle source
# File lib/domino/form.rb, line 77 def save find(self.class.submitter).click end
set(attributes = {})
click to toggle source
# File lib/domino/form.rb, line 73 def set(attributes = {}) attributes.each { |k, v| send("#{k}=", v) } end
update(attributes = {})
click to toggle source
# File lib/domino/form.rb, line 68 def update(attributes = {}) set(attributes) save end