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_on_format, ensure_set, extended, format, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, stage_method, view, write_tmp_file

Methods included from Event

#define_event, #event

Instance Method Details

#count(params = {}) ⇒ Object



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

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

#get_query(params = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'tmpsets/set/mod007-05_standard/type/search_type.rb', line 32

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

#item_cards(params = {}) ⇒ Object

~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/05_standard/set/type/search_type.rb ~~~~~~~~~~~



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
  Query.run(s, name)
end

#item_names(params = {}) ⇒ Object



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

def item_names params={}
  statement = query params.merge(return: :name)
  Query.run(statement, name)
end

#item_typeObject



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

def item_type
  return if query[:type].is_a?(Array) || query[:type].is_a?(Hash)
  query[:type]
end

#query(params = {}) ⇒ Object



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

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