Class: DcMemory

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
app/models/dc_memory.rb

Overview

Schema information

Collection name: dc_memory : Collection name used when form does not belong to database model.

_id                  BSON::ObjectId       _id

Which is not collection at all. DcMemory model is used for entering data on forms where data will not be saved to database but will instead be saved only to memory as temporary variable and processed by custom made methods. For example, define start and end date when making a timeline report.

Example (as used in forms):

table: dc_memory
title: Enter time period

  form:
    actions:
      1:
        type: ajax
        method: post
        controller: reports
        action: do_some_report
        caption: Run report

    fields:
      10:
        name: date_start
        type: date_picker
        caption: Start date
      20:
        name: date_end
        type: date_picker
        caption: End date

And suppose your report saved data to file named public/report.pdf. Put this line at the end of do_some_report method:

render inline: { :window_report => '/report.pdf' }.to_json, formats: 'js'

As result report.pdf file will be opened in new browser window.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

Method missing will return value if value defined by m parameter is saved to



116
117
118
119
120
121
122
123
124
125
# File 'app/models/dc_memory.rb', line 116

def method_missing(m, *args, &block) #:nodoc:
  @internals ||= {}
  m = m.to_s
  if m.match('=')
    m.chomp!('=')
    @internals[m] = args.first
  else
    @internals[m]
  end   
end

Instance Method Details

#[](field) ⇒ Object

Redefine [] method to act similar as send method



92
93
94
95
# File 'app/models/dc_memory.rb', line 92

def [](field)
  return nil unless @internals
  @internals[field.to_s]
end

#[]=(field, value) ⇒ Object

Redefine [] method to act similar as send method



100
101
102
103
# File 'app/models/dc_memory.rb', line 100

def []=(field, value)
  @internals ||= {}
  @internals[field.to_s] = value
end

#respond_to?(m) ⇒ Boolean

Respond_to should always return true.

Returns:

  • (Boolean)


73
74
75
# File 'app/models/dc_memory.rb', line 73

def respond_to?(m)
  true
end

#send(field, value = nil) ⇒ Object

Redefine send method. Send is used to assign value by cmsedit controller.



80
81
82
83
84
85
86
87
# File 'app/models/dc_memory.rb', line 80

def send(field,value=nil)
  field = field.to_s
  if field.match('=')
    field.chomp!('=')
    @internals ||= {}
    @internals[field] = value
  end
end

#to_sObject

For debugging purposes



108
109
110
# File 'app/models/dc_memory.rb', line 108

def to_s
  "DcMemory: @internals=#{@internals}"
end