Class: Thunk

Inherits:
Object
  • Object
show all
Defined in:
lib/thunk.rb,
lib/thunk/server.rb

Defined Under Namespace

Classes: Server

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, json) ⇒ Thunk

Returns a new instance of Thunk.



25
26
27
28
# File 'lib/thunk.rb', line 25

def initialize server, json
  @server = server
  apply json
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/thunk.rb', line 6

def name
  @name
end

#payloadObject (readonly)

Returns the value of attribute payload.



7
8
9
# File 'lib/thunk.rb', line 7

def payload
  @payload
end

#puuidObject (readonly)

Returns the value of attribute puuid.



8
9
10
# File 'lib/thunk.rb', line 8

def puuid
  @puuid
end

#stateObject (readonly)

Returns the value of attribute state.



9
10
11
# File 'lib/thunk.rb', line 9

def state
  @state
end

#updatedObject (readonly)

Returns the value of attribute updated.



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

def updated
  @updated
end

#uuidObject (readonly)

Returns the value of attribute uuid.



11
12
13
# File 'lib/thunk.rb', line 11

def uuid
  @uuid
end

Class Method Details

.create(*args) ⇒ Object



13
14
15
# File 'lib/thunk.rb', line 13

def self.create *args
  server.create *args
end

.get(*args) ⇒ Object



17
18
19
# File 'lib/thunk.rb', line 17

def self.get *args
  server.get *args
end

.serverObject



21
22
23
# File 'lib/thunk.rb', line 21

def self.server
  @server ||= Thunk::Server.new
end

Instance Method Details

#bad!(payload = nil) ⇒ Object



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

def bad! payload = nil
  poke :bad, payload
end

#bad?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/thunk.rb', line 30

def bad?
  :bad == state
end

#exists?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/thunk.rb', line 38

def exists?
  @server.request :get, url
end

#good!(payload = nil) ⇒ Object



46
47
48
# File 'lib/thunk.rb', line 46

def good! payload = nil
  poke :good, payload
end

#good?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/thunk.rb', line 42

def good?
  :good == state
end

#iffy!(payload = nil) ⇒ Object



54
55
56
# File 'lib/thunk.rb', line 54

def iffy! payload = nil
  poke :iffy, payload
end

#iffy?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/thunk.rb', line 50

def iffy?
  :iffy == state
end

#jsonObject

Used for the –raw option in the command-line client.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/thunk.rb', line 60

def json # :nodoc:
  json = {
    :name    => name,
    :payload => payload,
    :puuid   => puuid,
    :state   => state,
    :updated => updated,
    :url     => url,
    :uuid    => uuid
  }

  json.reject! { |k, v| v.nil? }
  JSON.generate json
end

#poke(state, payload = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/thunk.rb', line 75

def poke state, payload = nil
  if @server.request :post, "#{url}/#{state}", :payload => payload
    @payload = payload
    @state   = state.to_sym
    @updated = Time.now.utc
  end

  @state
end

#pokeable?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/thunk.rb', line 85

def pokeable?
  puuid
end

#public?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/thunk.rb', line 89

def public?
  !puuid
end

#unknown!(payload = nil) ⇒ Object



97
98
99
# File 'lib/thunk.rb', line 97

def unknown! payload = nil
  poke :unknown, payload
end

#unknown?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/thunk.rb', line 93

def unknown?
  :unknown == state
end

#urlObject



101
102
103
# File 'lib/thunk.rb', line 101

def url
  "#{@server.url}/#{uuid}"
end