Class: SuperSource::Organization

Inherits:
Object
  • Object
show all
Defined in:
lib/super_source/organization.rb

Constant Summary collapse

@@current_organization =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, id) ⇒ Organization

Returns a new instance of Organization.



9
10
11
12
# File 'lib/super_source/organization.rb', line 9

def initialize(name, id)
  @name = name
  @id = id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/super_source/organization.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/super_source/organization.rb', line 5

def name
  @name
end

Class Method Details

.current_organizationObject



34
35
36
# File 'lib/super_source/organization.rb', line 34

def self.current_organization
  @@current_organization ||= Organization.current_organization_from_file
end

.current_organization_filenameObject



14
15
16
# File 'lib/super_source/organization.rb', line 14

def self.current_organization_filename
  "#{ SuperSource.project_supso_config_root }/current_organization.json"
end

.current_organization_from_fileObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/super_source/organization.rb', line 18

def self.current_organization_from_file
  organization_data = {}
  begin
    organization_data = JSON.parse(File.read(Organization.current_organization_filename))
    organization_data = {} if !organization_data.is_a?(Object)
  rescue
    organization_data = {}
  end

  if organization_data['id']
    Organization.new(organization_data['name'], organization_data['id'])
  else
    nil
  end
end