Class: Glassfrog::Base

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/glassfrog/base.rb

Overview

Superclass of all GlassFrog classes.

Direct Known Subclasses

Action, ChecklistItem, Circle, Metric, Person, Project, Role, Trigger

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#extract_id, #parameterize, #symbolize_keys

Constructor Details

#initialize(attrs = {}) {|_self| ... } ⇒ Glassfrog::Base

Initializes a new Base object.

Parameters:

  • attrs (defaults to: {})

    {} [Hash] Attributes used to instantiate Base object.

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
21
22
# File 'lib/glassfrog/base.rb', line 17

def initialize(attrs = {})
  attrs.each do |key, value|
    instance_variable_set("@#{key}", value);
  end
  yield(self) if block_given?
end

Instance Attribute Details

#idInteger

Returns:

  • (Integer)


10
11
12
# File 'lib/glassfrog/base.rb', line 10

def id
  @id
end

Instance Method Details

#==(other) ⇒ Boolean

Check equality between two objects. Should be equal if they are the same type and their IDs are also equal.

Parameters:

Returns:

  • (Boolean)

    They are equal or not.



29
30
31
# File 'lib/glassfrog/base.rb', line 29

def ==(other)
  self.id == other.id && self.class == other.class
end

#hashifyHash

Turns the Base object into a hash.

Returns:

  • (Hash)

    Hash version of the Base object.



37
38
39
40
41
# File 'lib/glassfrog/base.rb', line 37

def hashify
  hash = Hash.new
  self.instance_variables.each { |var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) }
  symbolize_keys(hash)
end