Class: Restio::Connector::Generic

Inherits:
Object
  • Object
show all
Includes:
Util::Callback, Util::Header, Util::Url
Defined in:
lib/restio/connector/generic.rb

Direct Known Subclasses

Collection, Resource

Instance Attribute Summary collapse

Attributes included from Util::Callback

#callbacks

Attributes included from Util::Url

#base_url

Instance Method Summary collapse

Methods included from Util::Callback

#register_callback, #run_callbacks

Methods included from Util::Header

#add_header, #headers

Methods included from Util::Url

#url

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/restio/connector/generic.rb', line 14

def type
  @type
end

#use_backend_attributesObject

Returns the value of attribute use_backend_attributes.



13
14
15
# File 'lib/restio/connector/generic.rb', line 13

def use_backend_attributes
  @use_backend_attributes
end

#wrappedObject

Returns the value of attribute wrapped.



13
14
15
# File 'lib/restio/connector/generic.rb', line 13

def wrapped
  @wrapped
end

Instance Method Details

#cast(value) ⇒ Object



44
45
46
# File 'lib/restio/connector/generic.rb', line 44

def cast value
  caster.cast value
end

#casterObject



37
38
39
40
41
42
43
# File 'lib/restio/connector/generic.rb', line 37

def caster
  return @caster if @caster and not @update_caster
  @update_caster = false
  @caster_klass ||= "Restio::Util::Caster::Default"
  require @caster_klass.underscore
  @caster = @caster_klass.constantize.new
end

#caster=(caster) ⇒ Object



33
34
35
36
# File 'lib/restio/connector/generic.rb', line 33

def caster= caster
  @caster_klass = "Restio::Util::Caster::#{caster.to_s.classify}"
  @update_caster = true
end

#collection_nameObject



24
25
26
# File 'lib/restio/connector/generic.rb', line 24

def collection_name
  @klass.name.underscore.split('/').last.pluralize.to_s
end

#empty(response) ⇒ Object



18
19
20
# File 'lib/restio/connector/generic.rb', line 18

def empty response
  response.code == 204
end

#nameObject



27
28
29
30
31
32
# File 'lib/restio/connector/generic.rb', line 27

def name
  case type
  when :collection then collection_name
  when :resource   then resource_name
  end
end

#processable(response) ⇒ Object



15
16
17
# File 'lib/restio/connector/generic.rb', line 15

def processable response
  (200..299).include? response.code
end

#resource_nameObject



21
22
23
# File 'lib/restio/connector/generic.rb', line 21

def resource_name
  @klass.name.underscore.split('/').last.singularize.to_s
end

#unwrap(params = {}) ⇒ Object



47
48
49
# File 'lib/restio/connector/generic.rb', line 47

def unwrap params={}
  wrapped ? params[name] : params
end

#wrap(params) ⇒ Object



50
51
52
# File 'lib/restio/connector/generic.rb', line 50

def wrap params
  wrapped ? { name => params } : params
end