Module: Threatstack::Serializable

Included in:
Agent, Alert, Cve, GenericObject, Response, Rule, Ruleset
Defined in:
lib/threatstack/serializable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



15
16
17
# File 'lib/threatstack/serializable.rb', line 15

def method_missing(m, *args)
  raw[m.to_s] || raw[camelize(m.to_s)]
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/threatstack/serializable.rb', line 3

def client
  @client
end

#rawObject (readonly)

Returns the value of attribute raw.



3
4
5
# File 'lib/threatstack/serializable.rb', line 3

def raw
  @raw
end

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/threatstack/serializable.rb', line 5

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#attrsObject



19
20
21
# File 'lib/threatstack/serializable.rb', line 19

def attrs
  @attrs ||= self.class.default_attrs
end

#camelize(str) ⇒ Object



23
24
25
26
# File 'lib/threatstack/serializable.rb', line 23

def camelize(str)
  string = str.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
  string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
end

#initialize(raw, client, entity: nil) ⇒ Object



9
10
11
12
13
# File 'lib/threatstack/serializable.rb', line 9

def initialize(raw, client, entity: nil)
  @client = client
  @raw = raw
  @entity = entity
end