Class: OMF::SFA::Resource::OAccount

Inherits:
OGroup show all
Defined in:
lib/omf-sfa/resource/oaccount.rb

Overview

This class represents a users or team’s account. Each resource belongs to an account.

Constant Summary collapse

@@def_duration =

100 days

100 * 86400

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OGroup

#add_members, #all_resources, #each_resource, #empty_group, #group?, #member?, #members, #members=, #to_hash_long

Methods inherited from OResource

#_dirty_self?, #_oprops_to_hash, #all_resources, #clone, #default_href_prefix, #destroy, #destroy!, #dirty_self?, #each_resource, #group?, #href, href_resolver, init, json_create, #oproperties_as_hash, #oproperty, oproperty, #oproperty_array_get, #oproperty_get, #oproperty_set, prop_all, #remove_from_all_groups, #status, #to_hash, #to_hash_brief, #to_hash_long, #to_json, #uuid

Constructor Details

#initialize(*args) ⇒ OAccount

Returns a new instance of OAccount.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/omf-sfa/resource/oaccount.rb', line 58

def initialize(*args)
  super
  props = Hash.new
  args.each do |a|
    props.merge!(a)
  end
  self.created_at = Time.now
  if self.valid_until == nil
    self.valid_until = Time.now + @@def_duration
  end
end

Class Method Details

.default_duration=(duration) ⇒ Object



16
17
18
# File 'lib/omf-sfa/resource/oaccount.rb', line 16

def self.default_duration=(duration)
  @@def_duration = duration
end

.urn_typeObject



20
21
22
# File 'lib/omf-sfa/resource/oaccount.rb', line 20

def self.urn_type
  'account'
end

Instance Method Details

#active?Boolean

has n, :active_components, :model => ‘OResource’, :child_key => [ :account_id ] #, :required => false belongs_to :project, :required => false

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/omf-sfa/resource/oaccount.rb', line 34

def active?
  return false unless self.closed_at.nil?

  valid_until = self.valid_until
  unless valid_until.kind_of? Time
    valid_until = Time.parse(valid_until) # seem to not be returned as Time
  end
  if Time.now > valid_until
    self.close()
    return false
  end
  true
end

#closeObject

Close account



53
54
55
56
# File 'lib/omf-sfa/resource/oaccount.rb', line 53

def close
  self.closed_at = Time.now
  save
end

#closed?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/omf-sfa/resource/oaccount.rb', line 48

def closed?
  ! active?
end

#resource_typeObject



78
79
80
# File 'lib/omf-sfa/resource/oaccount.rb', line 78

def resource_type()
  'account'
end

#valid_untilObject



70
71
72
73
74
75
76
# File 'lib/omf-sfa/resource/oaccount.rb', line 70

def valid_until
  v = oproperty_get(:valid_until)
  if v && !v.kind_of?(Time)
    oproperty_set(:valid_until, v = Time.parse(v))
  end
  v
end