Module: CatForms::Form::InstanceMethods

Defined in:
lib/cat_forms.rb

Instance Method Summary collapse

Instance Method Details

#initialize(options = {}) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/cat_forms.rb', line 210

def initialize options = {}
  run_callbacks(:initialize) do
    # can sometimes be a string
    if options.class != Hash
      options = {}
    end
    options[:form] ||= {}

    # TODO fix
    # This allows setting of custom things
    options.each do |key, value|
      instance_variable_set "@#{key}", value
    end

    CatForms::GzipCookie.load(storage_options).each do |key, value|
      method = "#{key}="
      if respond_to?(method)
        self.send method, value
      end
    end

    options[:form].each do |name, value|
      value.strip! if value.respond_to?(:strip)
      self.send "#{name}=", value
    end

  end
  super
end

#persisted?Boolean

Need to look into all the below methods, not sure if they are correct.

Returns:



181
182
183
# File 'lib/cat_forms.rb', line 181

def persisted?
  false
end

#saveObject



201
202
203
204
205
206
207
208
# File 'lib/cat_forms.rb', line 201

def save
  run_callbacks :save do
    if !valid?
      return false
    end
  end
  self
end

#save_to_storage!Object



240
241
242
243
# File 'lib/cat_forms.rb', line 240

def save_to_storage!
  options = storage_options.merge(attributes: attributes)
  CatForms::GzipCookie.save(options)
end

#storage_optionsObject



245
246
247
248
249
250
251
# File 'lib/cat_forms.rb', line 245

def storage_options
  {
    cookie_name: @cookie_name,
    request: @request,
    response: @response
  }
end

#to_keyObject



197
198
199
# File 'lib/cat_forms.rb', line 197

def to_key
  nil
end

#to_modelObject



185
186
187
# File 'lib/cat_forms.rb', line 185

def to_model
  self
end

#to_paramObject



193
194
195
# File 'lib/cat_forms.rb', line 193

def to_param
  nil
end

#to_partial_pathObject



189
190
191
# File 'lib/cat_forms.rb', line 189

def to_partial_path
  "some_path" # TODO figure out what's needed here for Rails 3.2
end