Class: DuckForm
- Inherits:
-
Object
- Object
- DuckForm
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- lib/duck_form.rb,
lib/duck_form/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ DuckForm
constructor
A new instance of DuckForm.
- #persisted? ⇒ Boolean
- #update_attributes(attrs) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ DuckForm
Returns a new instance of DuckForm.
24 25 26 |
# File 'lib/duck_form.rb', line 24 def initialize attrs={} update_attributes attrs end |
Class Method Details
.build(name, *attrs, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/duck_form.rb', line 11 def self.build name, *attrs, &block defaults = attrs.last.is_a?(Hash) ? attrs.pop : {} klass = Class.new self klass.define_singleton_method :model_name do ActiveModel::Name.new self, nil, name.to_s end klass.class_eval do attr_accessor *(attrs + defaults.keys) end klass.class_eval(&block) if block klass.new defaults end |
Instance Method Details
#persisted? ⇒ Boolean
35 36 37 |
# File 'lib/duck_form.rb', line 35 def persisted? false end |
#update_attributes(attrs) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/duck_form.rb', line 28 def update_attributes attrs return unless attrs attrs.each_pair do |attr, val| send("#{attr}=", val) end end |