Class: RestKat::Resource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Resource

Returns a new instance of Resource.



4
5
6
# File 'lib/rest_kat.rb', line 4

def initialize resource
  self.hash = resource
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



3
4
5
# File 'lib/rest_kat.rb', line 3

def hash
  @hash
end

Instance Method Details

#c_bool(r) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/rest_kat.rb', line 72

def c_bool r
  if r
    "true"
  else
    "false"
  end
end

#c_permission_for(type) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/rest_kat.rb', line 32

def c_permission_for type
  if permissions.include? type
    "true"
  else
    "false"
  end
end

#cached?Boolean

Returns:

  • (Boolean)


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

def cached?
  self.hash[:cached]
end

#collection_keypathObject



24
25
26
# File 'lib/rest_kat.rb', line 24

def collection_keypath
  hash[:name]
end

#create?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/rest_kat.rb', line 44

def create?
  @create ||= permissions.include? 'c'
end

#delete?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/rest_kat.rb', line 56

def delete?
  @delete ||= permissions.include? 'd'
end

#item_keypathObject



28
29
30
# File 'lib/rest_kat.rb', line 28

def item_keypath
  hash[:name].singularize
end

#objc_classObject



16
17
18
# File 'lib/rest_kat.rb', line 16

def objc_class
  "MSRestResource#{hash[:name].camelize}"
end

#objc_resource_typeObject



12
13
14
# File 'lib/rest_kat.rb', line 12

def objc_resource_type
  hash[:type][:name]
end

#permissionsObject



20
21
22
# File 'lib/rest_kat.rb', line 20

def permissions
  hash[:permissions]
end

#queries(&block) ⇒ Object



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

def queries &block
  if hash.has_key?("queries")
    if block_given?
      hash["queries"].each &block 
    else
      hash["queries"]
    end
  else
    []
  end
end

#read?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rest_kat.rb', line 48

def read?
  @read ||= permissions.include? 'r'
end

#singleton?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rest_kat.rb', line 40

def singleton?
  @singleton ||= permissions.include? 's'
end

#update?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/rest_kat.rb', line 52

def update?
  @update ||= permissions.include? 'u'
end