Class: Afterburn::TrelloObjectWrapper

Inherits:
Object
  • Object
show all
Extended by:
Helpers
Includes:
Helpers
Defined in:
lib/afterburn/trello_object_wrapper.rb

Direct Known Subclasses

Board, List, Member

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

constantize, redis, titleize

Constructor Details

#initialize(trello_id = nil) {|_self| ... } ⇒ TrelloObjectWrapper

Returns a new instance of TrelloObjectWrapper.

Yields:

  • (_self)

Yield Parameters:



44
45
46
47
# File 'lib/afterburn/trello_object_wrapper.rb', line 44

def initialize(trello_id = nil)
  @id = trello_id
  yield self if block_given?
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/afterburn/trello_object_wrapper.rb', line 14

def id
  @id
end

Class Method Details

.fetch(id) ⇒ Object



26
27
28
29
# File 'lib/afterburn/trello_object_wrapper.rb', line 26

def self.fetch(id)
  return nil if id.nil?
  new(id).fetch
end

.find(id) ⇒ Object



21
22
23
24
# File 'lib/afterburn/trello_object_wrapper.rb', line 21

def self.find(id)
  return nil if id.nil?
  new(id).load
end

.inherited(base) ⇒ Object



9
10
11
12
# File 'lib/afterburn/trello_object_wrapper.rb', line 9

def self.inherited(base)
  base.send :include, Redis::Objects
  base.value :trello_object_store, :marshal => true
end

.initialize_from_trello_object(trello_object) ⇒ Object



31
32
33
# File 'lib/afterburn/trello_object_wrapper.rb', line 31

def self.initialize_from_trello_object(trello_object)
  new { |board| board.trello_object = trello_object }
end

.wrap(wrapper_name) ⇒ Object



16
17
18
19
# File 'lib/afterburn/trello_object_wrapper.rb', line 16

def self.wrap(wrapper_name)
  @wrapper_name = wrapper_name
  alias_method "trello_#{wrapper_name}", :trello_object
end

.wrapper_classObject



35
36
37
# File 'lib/afterburn/trello_object_wrapper.rb', line 35

def self.wrapper_class
  constantize("Trello::#{titleize(wrapper_name.to_s)}")
end

.wrapper_nameObject



39
40
41
42
# File 'lib/afterburn/trello_object_wrapper.rb', line 39

def self.wrapper_name
  raise "wrapper_name not defined for #{self}" unless @wrapper_name
  @wrapper_name
end

Instance Method Details

#fetchObject



58
59
60
61
62
63
# File 'lib/afterburn/trello_object_wrapper.rb', line 58

def fetch
  self.class.wrapper_class.find(id).tap do |fetched_object|
    self.trello_object = fetched_object
  end
  self
end

#loadObject



53
54
55
56
# File 'lib/afterburn/trello_object_wrapper.rb', line 53

def load
  trello_object
  self
end

#redis_key(*values) ⇒ Object



77
78
79
# File 'lib/afterburn/trello_object_wrapper.rb', line 77

def redis_key(*values)
  (["#{wrapper_name}:#{id}"] + values).join(":")
end

#trello_objectObject



71
72
73
74
75
# File 'lib/afterburn/trello_object_wrapper.rb', line 71

def trello_object
  return nil if id.nil?
  fetch if trello_object_store.value.nil?
  trello_object_store.value
end

#trello_object=(object) ⇒ Object



65
66
67
68
69
# File 'lib/afterburn/trello_object_wrapper.rb', line 65

def trello_object=(object)
  return nil if object.nil?
  @id = object.id
  trello_object_store.value = object
end

#wrapper_nameObject



49
50
51
# File 'lib/afterburn/trello_object_wrapper.rb', line 49

def wrapper_name
  self.class.wrapper_name
end