Module: SuperForm

Extended by:
ActiveSupport::Concern
Includes:
Fieldable
Defined in:
lib/super_form.rb,
lib/super_form/version.rb,
lib/super_form/fieldset.rb,
lib/super_form/fieldable.rb

Defined Under Namespace

Modules: ClassMethods, Fieldable Classes: Fieldset

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Fieldable

#field, #fields, #fieldset, #fieldsets

Class Method Details

.callbacksObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/super_form.rb', line 30

def self.callbacks
  Proc.new do
    alias_method :ar_valid?, :valid?

    def valid?
      run_callbacks :validation do
        ar_valid?
      end
    end

    define_model_callbacks :validation, :save
  end
end

.constructorObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/super_form.rb', line 19

def self.constructor
  Proc.new do
    alias_method :original_initializer, :initialize

    def initialize(*args)
      setup
      original_initializer(*args)
    end
  end
end

Instance Method Details

#persist!Object



65
# File 'lib/super_form.rb', line 65

def persist!; end

#persisted?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/super_form.rb', line 50

def persisted?
  false
end

#saveObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/super_form.rb', line 54

def save
  if valid?
    run_callbacks :save do
      persist!
    end
    true
  else
    false
  end
end

#setupObject



44
45
46
47
48
# File 'lib/super_form.rb', line 44

def setup
  if self.class.setup
    instance_eval(&self.class.setup)
  end
end