Module: Card::Set::Type::SearchType

Extended by:
Card::Set
Included in:
Set
Defined in:
tmpsets/set/mod007-05_standard/type/search_type.rb

Instance Method Summary collapse

Methods included from Card::Set

abstract_set?, all_set?, card_accessor, card_reader, card_writer, clean_empty_module_from_hash, clean_empty_modules, define_active_job, define_event_method, define_event_perform_later_method, define_on_format, ensure_set, event, extended, format, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, view, write_tmp_file

Instance Method Details

#count(params = {}) ⇒ Object



21
22
23
# File 'tmpsets/set/mod007-05_standard/type/search_type.rb', line 21

def count params={}
  Card.count_by_wql query( params )
end

#get_query(params = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'tmpsets/set/mod007-05_standard/type/search_type.rb', line 30

def get_query params={}
  query = Auth.as_bot do ## why is this a wagn_bot thing?  can't deny search content??
    query_content = params.delete(:query) || raw_content
    #warn "get_query #{name}, #{query_content}, #{params.inspect}"
    raise("Error in card '#{self.name}':can't run search with empty content") if query_content.empty?
    String === query_content ? JSON.parse( query_content ) : query_content
  end
  query.symbolize_keys!.merge! params.symbolize_keys
  if default_limit = query.delete(:default_limit) and !query[:limit]
    query[:limit] = default_limit
  end
  query[:context] ||= (cardname.junction? ? cardname.left_name : cardname)
  query
end

#item_cards(params = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'tmpsets/set/mod007-05_standard/type/search_type.rb', line 5

def item_cards params={}
  s = query(params)
  raise("OH NO.. no limit") unless s[:limit]
  # forces explicit limiting
  # can be 0 or less to force no limit
  Card.search( s )
end

#item_names(params = {}) ⇒ Object



13
14
15
# File 'tmpsets/set/mod007-05_standard/type/search_type.rb', line 13

def item_names params={}
  Card.search(query(params.merge(:return=>:name)))
end

#item_typeObject



17
18
19
# File 'tmpsets/set/mod007-05_standard/type/search_type.rb', line 17

def item_type
  query[:type]
end

#query(params = {}) ⇒ Object



25
26
27
28
# File 'tmpsets/set/mod007-05_standard/type/search_type.rb', line 25

def query params={}
  @query ||= {}
  @query[params.to_s] ||= get_query(params.clone)
end