Class: DcMemory
- Inherits:
-
Object
- Object
- DcMemory
- 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.
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
-
#[](field) ⇒ Object
Redefine [] method to act similar as send method.
-
#[]=(field, value) ⇒ Object
Redefine [] method to act similar as send method.
-
#id ⇒ Object
Return id field.
-
#id=(value) ⇒ Object
Respond_to should always return true.
-
#initialize(parms = {}) ⇒ DcMemory
constructor
Initilize object.
-
#method_missing(m, *args, &block) ⇒ Object
Method missing will return value if value defined by m parameter is saved to.
-
#respond_to?(m) ⇒ Boolean
Respond_to should always return true.
-
#send(field, value = nil) ⇒ Object
Redefine send method.
-
#to_s ⇒ Object
For debugging purposes.
Constructor Details
#initialize(parms = {}) ⇒ DcMemory
Initilize object
71 72 73 74 |
# File 'app/models/dc_memory.rb', line 71 def initialize(parms = {}) @internals = {} parms.each { |key, value| @internals[key.to_s] = value } if parms end |
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
138 139 140 141 142 143 144 145 146 147 |
# File 'app/models/dc_memory.rb', line 138 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
114 115 116 117 |
# File 'app/models/dc_memory.rb', line 114 def [](field) return nil unless @internals @internals[field.to_s] end |
#[]=(field, value) ⇒ Object
Redefine [] method to act similar as send method
122 123 124 125 |
# File 'app/models/dc_memory.rb', line 122 def []=(field, value) @internals ||= {} @internals[field.to_s] = value end |
#id ⇒ Object
Return id field
79 80 81 |
# File 'app/models/dc_memory.rb', line 79 def id() @internals['id'] end |
#id=(value) ⇒ Object
Respond_to should always return true.
86 87 88 |
# File 'app/models/dc_memory.rb', line 86 def id=(value) @internals['id'] = value end |
#respond_to?(m) ⇒ Boolean
Respond_to should always return true.
93 94 95 |
# File 'app/models/dc_memory.rb', line 93 def respond_to?(m) true end |
#send(field, value = nil) ⇒ Object
Redefine send method. Send is used to assign or access value by cmsedit controller.
100 101 102 103 104 105 106 107 108 109 |
# File 'app/models/dc_memory.rb', line 100 def send(field,value=nil) field = field.to_s if field.match('=') field.chomp!('=') @internals ||= {} @internals[field] = value else @internals[field] end end |
#to_s ⇒ Object
For debugging purposes
130 131 132 |
# File 'app/models/dc_memory.rb', line 130 def to_s "DcMemory: @internals=#{@internals.size} #{@internals}" end |