Class: Cardiac::BaseReflection

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

Direct Known Subclasses

ResourceReflection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_or_uri, http_verb = nil) ⇒ BaseReflection

Returns a new instance of BaseReflection.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cardiac/reflections.rb', line 15

def initialize(resource_or_uri, http_verb=nil)
  @macro, @http_verb = self.class.build_macro, http_verb

  resource_or_uri.to_resource if resource_or_uri.respond_to?(:to_resource)
      
  case resource_or_uri
  when Cardiac::Resource
    @http_verb ||= resource_or_uri.method_value
    @uri = resource_or_uri.to_uri
    _options = resource_or_uri.send(:build_client_options, @http_verb)
  when URI
    @uri = resource_or_uri.dup
    _options = {}
  else
    @uri = resource_or_uri.to_uri if resource_or_uri.respond_to?(:to_uri)
    @http_verb ||= resource_or_uri.http_verb if resource_or_uri.respond_to?(:http_verb)
    @options ||= resource_or_uri.options if resource_or_uri.respond_to?(:options)
  end
  @options = _options.dup
  @options.symbolize_keys!
  @options[:method] = @http_verb
end

Instance Attribute Details

#http_verbObject (readonly) Also known as: http_verb?, http_method

Returns the value of attribute http_verb.



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

def http_verb
  @http_verb
end

#macroObject (readonly)

Returns the value of attribute macro.



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

def macro
  @macro
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

Instance Method Details

#to_reflectionObject



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

def to_reflection
  self
end

#to_uriObject



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

def to_uri
  @uri.dup
end

#to_urlObject



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

def to_url
  @uri.to_s
end