Class: Timberline::Envelope

Inherits:
Object
  • Object
show all
Defined in:
lib/timberline/envelope.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEnvelope

Returns a new instance of Envelope.



14
15
16
# File 'lib/timberline/envelope.rb', line 14

def initialize
  @metadata = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/timberline/envelope.rb', line 24

def method_missing(method_name, *args)
  method_name = method_name.to_s
  if method_name[-1] == "="
    assign_var(method_name[0, method_name.size - 1], args.first)
  else
    return [method_name]
  end
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



11
12
13
# File 'lib/timberline/envelope.rb', line 11

def contents
  @contents
end

#metadataObject (readonly)

Returns the value of attribute metadata.



12
13
14
# File 'lib/timberline/envelope.rb', line 12

def 
  @metadata
end

Class Method Details

.from_json(json_string) ⇒ Object



4
5
6
7
8
9
# File 'lib/timberline/envelope.rb', line 4

def self.from_json(json_string)
  envelope = Envelope.new
  envelope.instance_variable_set("@metadata", JSON.parse(json_string))
  envelope.contents = envelope..delete("contents")
  envelope
end

Instance Method Details

#to_sObject



18
19
20
21
22
# File 'lib/timberline/envelope.rb', line 18

def to_s
  raise MissingContentException if contents.nil? || contents.empty?

  JSON.unparse(build_envelope_hash)
end