Class: ResourceFull::Query::Parameter

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

Overview

A Parameter represents the information necessary to describe a query relationship. It’s inherently tied to ActiveRecord at the moment, unfortunately. Objects of this class should not be instantiated directly; instead, use the queryable_with method.

Direct Known Subclasses

CustomParameter, OrderParameter, ScopedParameter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, resource, opts = {}) ⇒ Parameter

Returns a new instance of Parameter.



19
20
21
22
23
24
25
# File 'lib/resource_full/query.rb', line 19

def initialize(name, resource, opts={})
  @name      = name
  @resource  = resource
  @fuzzy     = opts[:fuzzy] || false
  @allow_nil = opts[:allow_nil] || false
  @default_value = opts[:default]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#resourceObject (readonly)

Returns the value of attribute resource.



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

def resource
  @resource
end

Instance Method Details

#allow_nil?Boolean

Returns:

  • (Boolean)


28
# File 'lib/resource_full/query.rb', line 28

def allow_nil?; @allow_nil; end

#applicable_to?(request_params) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
# File 'lib/resource_full/query.rb', line 38

def applicable_to?(request_params)
  if allow_nil?
    request_params.has_key?(self.name.to_s) || request_params.has_key?(self.name.to_s.pluralize)
  else
    not param_values_for(request_params).blank?
  end
end

#find(finder, request_params) ⇒ Object

Raises:

  • (NotImplementedError)


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

def find(finder, request_params)
  raise NotImplementedError, "Subclasses implement this behavior."
end

#fuzzy?Boolean

Returns:

  • (Boolean)


27
# File 'lib/resource_full/query.rb', line 27

def fuzzy?; @fuzzy; end

#subclass(new_resource) ⇒ Object

Raises:

  • (NotImplementedError)


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

def subclass(new_resource)
  raise NotImplementedError, "Subclasses implement this behavior."
end

#to_xml(opts = {}) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/resource_full/query.rb', line 30

def to_xml(opts={})
  {
    :name => name.to_s,
    :resource => resource.model_name.pluralize,
    :fuzzy => fuzzy?,
  }.to_xml(opts.merge(:root => "parameter"))
end