Class: Stratagem::Instrumentation::Models::Persistence::Common::Metadata
- Defined in:
- lib/stratagem/instrumentation/models/persistence/common/metadata.rb
Overview
prefix method names with to avoid collision
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #attribute_names ⇒ Object
-
#ignore_attributes ⇒ Object
junk attributes.
-
#initialize(model) ⇒ Metadata
constructor
A new instance of Metadata.
Constructor Details
#initialize(model) ⇒ Metadata
Returns a new instance of Metadata.
8 9 10 11 12 13 14 15 |
# File 'lib/stratagem/instrumentation/models/persistence/common/metadata.rb', line 8 def initialize(model) @model = model begin @instance = @model.new unless (@model == ActiveRecord::Base) rescue puts "ERROR: #{@model.name} could not be instantiated: #{$!.}" end end |
Instance Attribute Details
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
6 7 8 |
# File 'lib/stratagem/instrumentation/models/persistence/common/metadata.rb', line 6 def instance @instance end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/stratagem/instrumentation/models/persistence/common/metadata.rb', line 6 def model @model end |
Instance Method Details
#attribute_names ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stratagem/instrumentation/models/persistence/common/metadata.rb', line 17 def attribute_names @attribute_names ||= begin names = model.new.methods.select {|m| s = m.to_s if (s.to_s =~ /=$/) name = s.gsub(/=$/, '') name.singularize == name else false end }.map {|m| m.to_s.gsub(/=$/, '').to_sym } names - (model.stratagem.internal_attributes + model.stratagem.ignore_attributes + model.stratagem.relation_names) end end |
#ignore_attributes ⇒ Object
junk attributes
35 36 37 |
# File 'lib/stratagem/instrumentation/models/persistence/common/metadata.rb', line 35 def ignore_attributes @ignore_attributes ||= ["!", "[]", "===", "==", "=", "taguri"].map {|a| a.to_sym } end |