Module: TransForms::MainModel::Proxy

Extended by:
ActiveSupport::Concern
Includes:
Active
Defined in:
lib/trans_forms/main_model/proxy.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from Active

#errors, #main_instance, #model=

Instance Method Details

#persisted?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/trans_forms/main_model/proxy.rb', line 15

def persisted?
  respond_to?(:main_instance) && main_instance && main_instance.persisted?
end

#to_keyObject

Returns an Enumerable of all key attributes of the main instanceif any is set, regardless if the object is persisted or not. Returns nil if there is no main_instance or if main_instance have no key attributes.

class UserForm < TransForms::BaseForm
  set_main_model :user, proxy: true
end

form = UserForm.new
form.to_key # => nil

form.user = User.new
form.to_key # => nil

form.user.save # => true
form.to_key # => [1]


41
42
43
# File 'lib/trans_forms/main_model/proxy.rb', line 41

def to_key
  respond_to?(:main_instance) && main_instance && main_instance.to_key
end

#to_paramObject

In case the Main Model has implemented custom to_param method, we need to make sure we use it here as well



21
22
23
# File 'lib/trans_forms/main_model/proxy.rb', line 21

def to_param
  respond_to?(:main_instance) && main_instance && main_instance.to_param || super
end