Module: DynamicRecordsMeritfront
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/dynamic-records-meritfront.rb,
lib/dynamic-records-meritfront/version.rb
Overview
this file contains multiple classes which should honestly be split up.
Defined Under Namespace
Modules: ClassMethods Classes: DynamicSqlVariables, MultiRowExpression
Constant Summary collapse
- VERSION =
'3.1.34'
Instance Method Summary collapse
- #has_association?(*args) ⇒ Boolean
-
#headache_preload(records, associations) ⇒ Object
just for ease of use.
-
#hgid(tag: nil) ⇒ Object
(also: #ghid)
custom hash GlobalID.
- #hgid_as_selector(tag: nil, attribute: 'id') ⇒ Object
- #inspect ⇒ Object
- #list_associations ⇒ Object
- #questionable_attribute_set(atr, value, as_default: false, push: false) ⇒ Object
Instance Method Details
#has_association?(*args) ⇒ Boolean
999 1000 1001 1002 |
# File 'lib/dynamic-records-meritfront.rb', line 999 def has_association?(*args) #just redirects to the class method for ease of use (see class method above) self.class.has_association?(*args) end |
#headache_preload(records, associations) ⇒ Object
just for ease of use
1022 1023 1024 |
# File 'lib/dynamic-records-meritfront.rb', line 1022 def headache_preload(records, associations) self.class.headache_preload(records, associations) end |
#hgid(tag: nil) ⇒ Object Also known as: ghid
custom hash GlobalID
1005 1006 1007 1008 1009 1010 1011 1012 |
# File 'lib/dynamic-records-meritfront.rb', line 1005 def hgid(tag: nil) gid = "gid://#{PROJECT_NAME}/#{self.class.to_s}/#{self.hid}" if !tag gid else "#{gid}@#{tag}" end end |
#hgid_as_selector(tag: nil, attribute: 'id') ⇒ Object
1015 1016 1017 1018 1019 |
# File 'lib/dynamic-records-meritfront.rb', line 1015 def hgid_as_selector(tag: nil, attribute: 'id') #https://www.javascripttutorial.net/javascript-dom/javascript-queryselector/ gidstr = hgid(tag: tag).to_s return self.class.string_as_selector(gidstr, attribute: attribute) end |
#inspect ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/dynamic-records-meritfront.rb', line 284 def inspect #basically the same as the upstream active record function (as of october 25 2022 on AR V7.0.4) #except that I changed self.class.attribute_names -> self.attribute_names to pick up our #dynamic insanity. Was this a good idea? Well I guess its better than not doing it #I also added dynamic_reflections inspection = if defined?(@attributes) && @attributes self.attribute_names.filter_map do |name| if _has_attribute?(name) "#{name}: #{attribute_for_inspect(name)}" end end.join(", ") else "not initialized" end self.dynamic_reflections ||= [] dyna = self.dynamic_reflections.map{|dr| [dr, self.method(dr.to_sym).call()] }.to_h if dyna.keys.any? "#<#{self.class} #{inspection} | #{dyna.to_s}>" else "#<#{self.class} #{inspection}>" end end |
#list_associations ⇒ Object
994 995 996 997 |
# File 'lib/dynamic-records-meritfront.rb', line 994 def list_associations #lists associations (see class method above) self.class.list_associations end |
#questionable_attribute_set(atr, value, as_default: false, push: false) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/dynamic-records-meritfront.rb', line 164 def questionable_attribute_set(atr, value, as_default: false, push: false) #this is needed on initalization of a new variable after the actual thing has been made already. #this is used for attaching records to other records in one-to-one or one-to-many #basically the way this works is by using singletons to paper over the fact that normal reflections #even exist. We dont integrate at all with their patterns as they use some crazy delegation stuff #that messes just about everything up. #man i thought i was meta coding, these association people just want to see the world burn. #keeping the old code commented for a while because this area keeps breaking and i want a log of what i have tried. self.dynamic_reflections ||= [] unless dynamic_reflections.include?(atr.to_s) self.dynamic_reflections << atr.to_s singleton_class.instance_eval do attr_accessor atr.to_sym end end # # if _reflections.keys.include? atr.to_s # has_method = methods.include?(atr.to_sym) # # DevScript.ping(has_method) # override = (not(has_method) or ( # _reflections.keys.include? atr.to_s # and not # ) # DevScript.ping(override) # if override # end #elsif #end # pi = atr.to_sym == :current_user_follow #DevScript.ping(self.inspect) if pi if as_default if self.method(atr.to_sym).call().nil? self.method("#{atr}=".to_sym).call(value) # Rails.logger.info "Y #{value.followable_type if value.respond_to? :followable_type}" if pi end # Rails.logger.info "#{atr} ||= #{value}" if pi elsif push self.method(atr.to_sym).call().push value # Rails.logger.info #{atr} << #{value}" if pi # DevScript.ping("atr #{atr} push #{value}") else #out = self.method("#{atr}=".to_sym).call(value) # Rails.logger.info "[#{self.class.to_s} #{self.id}].#{atr} -> #{out.inspect}" if pi # DevScript.ping("atr #{atr} set #{value}") end #Rails.logger.info self.inspect if pi # raise StandardError.new('bad options') if as_default and push # if as_default # unless self.respond_to? atr # #make sure its accesible in some way # values = @attributes.instance_variable_get(:@values) # if not values.keys.include?(atr) # values[atr] = value # end # end # else # if self.reflections.keys.include? atr.to_s # # else # values ||= @attributes.instance_variable_get(:@values) # values[atr] << value # # # end # #no getter/setter methodsout, probably catches missing methods and then redirects to attributes. Lots of magic. # # After multiple attempts, I gave up, so now we use eval. I guess I cant be too mad about magic as # # that seems to be my bread and butter. Hope eval doesnt make it go too slow. Guess everything is evaled # # on some level though? # s = self #afraid self will be a diffrent self in eval. Possibly depending on parser. IDK. Just seemed risky. # if push # eval "s.#{atr} << value" # else # eval "s.#{atr} = value" # end # end # atr = atr.to_s # setter = "#{atr}=" # if respond_to?(setter) # #this allows us to attach to ActiveRecord relations and standard columns as we expect. # #accessors etc will be triggered as expected. # if push # method(atr).call().push(value) # else # method(setter).call(value) # end # else # #for non-standard columns (one that is not expected by the record), # #this allows us to attach to the record, and access the value as we are acustomed to. # #when you 'save!' it interestingly seems to know thats not a normal column expected by # #the model, and will ignore it. # values = @attributes.instance_variable_get(:@values) # else # if as_default # self[atr] = value if self[atr].nil? # else # if push # self[atr] << value # else # self[atr] = value # end # end # end # end end |