Module: FmStore::Layout
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/fm_store/layout.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #attributes ⇒ Object
- #fm_attributes ⇒ Object
- #id ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #reload ⇒ Object
- #to_key ⇒ Object
-
#to_model ⇒ Object
Require by ActiveModel.
- #to_param ⇒ Object
Instance Method Details
#attributes ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fm_store/layout.rb', line 107 def attributes @attributes = {} fields.each do |fm_attr, field| ivar = send("#{field.name}") @attributes[field.name] = ivar end return @attributes end |
#fm_attributes ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fm_store/layout.rb', line 76 def fm_attributes attrs = {} fields.each do |fm_attr, field| ivar = send("#{field.name}") type = field.type if type == Date ivar = ivar.strftime("%m/%d/%Y") if ivar elsif type == DateTime ivar = ivar.strftime("%m/%d/%Y %H:%M:%S") if ivar elsif type == Time ivar = ivar.strftime("%H:%M") if ivar end # case ivar # when Date # ivar = ivar.strftime("%m/%d/%Y") # when DateTime # ivar = ivar.strftime("%m/%d/%Y %H:%M:%S") # when Time # ivar = ivar.strftime("%H:%M") # end attrs[fm_attr] = ivar if ivar # ignore nil attributes end attrs end |
#id ⇒ Object
123 124 125 |
# File 'lib/fm_store/layout.rb', line 123 def id self.class.identity == "-recid" ? @record_id : send(self.class.fields[self.class.identity].name) end |
#initialize(attributes = {}) ⇒ Object
70 71 72 73 74 |
# File 'lib/fm_store/layout.rb', line 70 def initialize(attributes = {}) @associations = {} @new_record = true process(attributes) end |
#new_record? ⇒ Boolean
127 128 129 |
# File 'lib/fm_store/layout.rb', line 127 def new_record? @new_record end |
#persisted? ⇒ Boolean
144 145 146 |
# File 'lib/fm_store/layout.rb', line 144 def persisted? !new_record? end |
#reload ⇒ Object
118 119 120 121 |
# File 'lib/fm_store/layout.rb', line 118 def reload @associations = {} self.class.id(id) end |
#to_key ⇒ Object
140 141 142 |
# File 'lib/fm_store/layout.rb', line 140 def to_key id if id end |
#to_model ⇒ Object
Require by ActiveModel
136 137 138 |
# File 'lib/fm_store/layout.rb', line 136 def to_model self end |
#to_param ⇒ Object
131 132 133 |
# File 'lib/fm_store/layout.rb', line 131 def to_param id.to_s if id end |