Class: Saint::ClassApi::Subset

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/saint/api/class/subset.rb

Constant Summary

VAR =
'saint-subsets'

Constants included from Utils

Utils::BOOLEAN_FILTERS, Utils::BOOLEAN_OPTIONS

Instance Method Summary (collapse)

Methods included from Utils

column_format, escape_html, #format_date__time, normalize_string, number_to_human_size, saint_view, unescape_html

Constructor Details

- (Subset) initialize(controller, column, filters, params = {})

Returns a new instance of Subset



30
31
32
33
34
35
36
# File 'lib/saint/api/class/subset.rb', line 30

def initialize controller, column, filters, params = {}
  @controller, @params = controller, params
  @column, @filters = column, filters
  if @params[VAR].is_a?(Hash) && active_filter = @params[VAR][column.to_s]
    @filters.each_key { |f| @active_filter = f if f == active_filter }
  end
end

Instance Method Details

- (Object) html



46
47
48
49
50
51
52
53
54
55
# File 'lib/saint/api/class/subset.rb', line 46

def html
  @filters.map do |filter, setup|
    {
        name: query_string,
        value: filter,
        label: setup.first,
        active: filter == @active_filter
    }
  end
end

- (Object) http



42
43
44
# File 'lib/saint/api/class/subset.rb', line 42

def http
  @active_filter ? '%s=%s' % [query_string, @active_filter] : []
end

- (Object) orm



38
39
40
# File 'lib/saint/api/class/subset.rb', line 38

def orm
  @active_filter ? {@column => @filters[@active_filter].last} : {}
end