Class: Stratagem::Instrumentation::Models::Persistence::Common::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/stratagem/instrumentation/models/persistence/common/metadata.rb

Overview

prefix method names with to avoid collision

Instance Attribute Summary collapse

Instance Method Summary collapse

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: #{$!.message}"
  end
end

Instance Attribute Details

#instanceObject (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

#modelObject (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_namesObject



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_attributesObject

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