Class: ActivePublicResources::RequestCriteria

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serialization
Defined in:
lib/active_public_resources/request_criteria.rb

Constant Summary collapse

SORTS =
[
  SORT_RELEVANCE = 'relevance',
  SORT_RECENT    = 'recent',
  SORT_POPULAR   = 'popular'
]
CONTENT_FILTERS =
[
  CONTENT_FILTER_NONE   = 'none',
  CONTENT_FILTER_STRICT = 'strict'
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ RequestCriteria

Returns a new instance of RequestCriteria.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_public_resources/request_criteria.rb', line 18

def initialize(args={})
  args.each do |k,v|
    if k.to_s == 'sort' && !SORTS.include?(v)
      raise ArgumentError.new("sort is invalid. Must be in [#{SORTS.join(', ')}]")
    end
    if k.to_s == 'content_filter' && !CONTENT_FILTERS.include?(v)
      raise ArgumentError.new("content_filter is invalid. Must be in [#{CONTENT_FILTERS.join(', ')}]")
    end
    instance_variable_set("@#{k}", v) unless v.nil?
  end
end

Instance Attribute Details

#content_filterObject

Returns the value of attribute content_filter.



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

def content_filter
  @content_filter
end

#folderObject

Returns the value of attribute folder.



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

def folder
  @folder
end

#pageObject

Returns the value of attribute page.



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

def page
  @page
end

#per_pageObject

Returns the value of attribute per_page.



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

def per_page
  @per_page
end

#queryObject

Returns the value of attribute query.



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

def query
  @query
end

#sortObject

Returns the value of attribute sort.



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

def sort
  @sort
end

Instance Method Details

#attributesObject



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

def attributes
  instance_values
end

#validate_presence!(attr_names) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/active_public_resources/request_criteria.rb', line 44

def validate_presence!(attr_names)
  attr_names.each do |k|
    if instance_variable_get("@#{k}").blank?
      raise ArgumentError.new("must include #{attr_names.join(', ')}")
    end
  end
end