Class: ActiveForm

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
lib/active_form.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = nil) {|_self| ... } ⇒ ActiveForm

Returns a new instance of ActiveForm.

Yields:

  • (_self)

Yield Parameters:

  • _self (ActiveForm)

    the object that the method was called on



15
16
17
18
19
20
21
22
23
# File 'lib/active_form.rb', line 15

def initialize(attributes = nil)
  # Mass Assignment implementation
  if attributes
    attributes.each do |key, value|
      self[key] = value
    end
  end
  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *params) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/active_form.rb', line 33

def method_missing(method_id, *params)
  # Implement _before_type_cast accessors
  if md = /_before_type_cast$/.match(method_id.to_s)
    attr_name = md.pre_match
    return self[attr_name] if self.respond_to?(attr_name)
  end
  super
end

Class Method Details

.raise_not_implemented_error(*params) ⇒ Object Also known as: create, create!, validates_acceptance_of, validates_uniqueness_of, validates_associated, validates_on_create, validates_on_update, save_with_validation

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/active_form.rb', line 64

def raise_not_implemented_error(*params)
  raise NotImplementedError
end

Instance Method Details

#[](key) ⇒ Object



25
26
27
# File 'lib/active_form.rb', line 25

def [](key)
  instance_variable_get("@#{key}")
end

#[]=(key, value) ⇒ Object



29
30
31
# File 'lib/active_form.rb', line 29

def []=(key, value)
  instance_variable_set("@#{key}", value)
end

#idObject



46
47
48
# File 'lib/active_form.rb', line 46

def id
  nil
end

#new_record?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/active_form.rb', line 42

def new_record?
  true
end

#persisted?Boolean

Returns:

  • (Boolean)


11
# File 'lib/active_form.rb', line 11

def persisted?; false; end

#raise_not_implemented_error(*params) ⇒ Object



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

def raise_not_implemented_error(*params)
  self.class.raise_not_implemented_error(params)
end

#save!Object



55
56
57
# File 'lib/active_form.rb', line 55

def raise_not_implemented_error(*params)
  self.class.raise_not_implemented_error(params)
end

#to_keyObject



12
# File 'lib/active_form.rb', line 12

def to_key; nil; end

#to_modelObject



10
# File 'lib/active_form.rb', line 10

def to_model; self; end

#to_paramObject



13
# File 'lib/active_form.rb', line 13

def to_param; nil; end

#update_attributeObject



56
57
58
# File 'lib/active_form.rb', line 56

def raise_not_implemented_error(*params)
  self.class.raise_not_implemented_error(params)
end

#update_attributesObject



57
58
59
# File 'lib/active_form.rb', line 57

def raise_not_implemented_error(*params)
  self.class.raise_not_implemented_error(params)
end