Class: Yapt::Member
- Inherits:
-
Object
- Object
- Yapt::Member
- Defined in:
- lib/yapt/member.rb
Instance Attribute Summary collapse
-
#membership ⇒ Object
readonly
Returns the value of attribute membership.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(membership) ⇒ Member
constructor
A new instance of Member.
- #initials ⇒ Object
Constructor Details
#initialize(membership) ⇒ Member
Returns a new instance of Member.
14 15 16 |
# File 'lib/yapt/member.rb', line 14 def initialize(membership) @membership = membership end |
Instance Attribute Details
#membership ⇒ Object (readonly)
Returns the value of attribute membership.
13 14 15 |
# File 'lib/yapt/member.rb', line 13 def membership @membership end |
Class Method Details
.all ⇒ Object
22 23 24 |
# File 'lib/yapt/member.rb', line 22 def self.all @memberships ||= cache[:results] end |
.cache ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/yapt/member.rb', line 26 def self.cache if File.exists?(Yapt.tracker_member_cache) cache = YAML.load_file(Yapt.tracker_member_cache) end expires_at = cache ? cache[:expires_at] : Time.new(0) expires_at > Time.now ? cache : generate_cache end |
.find(id) ⇒ Object
5 6 7 |
# File 'lib/yapt/member.rb', line 5 def self.find(id) new (all.detect {|u| u["person"]["id"] == id } || inactive_user) end |
.generate_cache ⇒ Object
34 35 36 37 38 39 |
# File 'lib/yapt/member.rb', line 34 def self.generate_cache results = Request.new("memberships").result to_cache = { results: results, expires_at: Time.now + Yapt.cache_duration } File.open(Yapt.tracker_member_cache, 'w') {|f| f.write to_cache.to_yaml } to_cache end |
.inactive_user ⇒ Object
9 10 11 |
# File 'lib/yapt/member.rb', line 9 def self.inactive_user { "person" => { "initials" => '???' } } end |
Instance Method Details
#initials ⇒ Object
18 19 20 |
# File 'lib/yapt/member.rb', line 18 def initials membership["person"]["initials"] end |