Class: ResourceFull::Query::CustomParameter

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

Instance Attribute Summary collapse

Attributes inherited from Parameter

#name, #resource

Instance Method Summary collapse

Methods inherited from Parameter

#applicable_to?, #fuzzy?, #to_xml

Constructor Details

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

Returns a new instance of CustomParameter.



87
88
89
90
91
92
93
94
# File 'lib/resource_full/query.rb', line 87

def initialize(name, resource, opts={})
  super(name, resource, opts)
  
  @table     = table_for(opts)
  @columns   = columns_for(name, resource, opts)
  @negated   = opts[:negated] || false
  @include   = opts[:from] || []
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



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

def columns
  @columns
end

#includeObject (readonly)

Returns the value of attribute include.



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

def include
  @include
end

#tableObject (readonly)

Returns the value of attribute table.



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

def table
  @table
end

Instance Method Details

#allow_nil?Boolean

Returns:

  • (Boolean)


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

def allow_nil?; @allow_nil; end

#find(finder, request_params) ⇒ Object



99
100
101
102
# File 'lib/resource_full/query.rb', line 99

def find(finder, request_params)
  return finder unless applicable_to?(request_params)
  finder.scoped :conditions => conditions_for(request_params), :include => @include
end

#negated?Boolean

Returns:

  • (Boolean)


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

def negated?; @negated; end

#subclass(new_resource) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/resource_full/query.rb', line 104

def subclass(new_resource)
  new_table = if @table == @resource.model_class.table_name
    new_resource.model_class.table_name
  else @table end
    
  self.class.new(@name, new_resource,
    :fuzzy     => @fuzzy,
    :allow_nil => @allow_nil,
    :table     => new_table,
    :columns   => @columns,
    :from      => @include,
    :negated   => @negated
  )
end