Module: Marquery::Query::ClassMethods

Defined in:
lib/marquery/query.rb

Instance Method Summary collapse

Instance Method Details

#all_entriesObject



89
90
91
92
# File 'lib/marquery/query.rb', line 89

def all_entries
  load! unless loaded?
  @marquery_data.entries
end

#assets_dir(path = nil) ⇒ Object



52
53
54
55
# File 'lib/marquery/query.rb', line 52

def assets_dir(path = nil)
  @assets_dir = path.to_s unless path.nil?
  @assets_dir
end

#assets_pathObject



61
62
63
64
65
# File 'lib/marquery/query.rb', line 61

def assets_path
  return nil unless assets_dir

  File.join(Marquery.config.data_dir, assets_dir)
end

#data_pathObject



57
58
59
# File 'lib/marquery/query.rb', line 57

def data_path
  File.join(Marquery.config.data_dir, dir)
end

#dir(path = nil) ⇒ Object



47
48
49
50
# File 'lib/marquery/query.rb', line 47

def dir(path = nil)
  @dir = path.to_s if path
  @dir ||= derive_dir
end

#index(klass = nil) ⇒ Object



34
35
36
37
# File 'lib/marquery/query.rb', line 34

def index(klass = nil)
  @marquery_index = klass if klass
  @marquery_index
end

#index_entryObject



94
95
96
97
# File 'lib/marquery/query.rb', line 94

def index_entry
  load! unless loaded?
  @marquery_data.index
end

#load!Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/marquery/query.rb', line 71

def load!
  @marquery_data = Marquery::Parser.new(
    dir: data_path,
    assets_dir: assets_path,
    model: model,
    index: index,
    order_by: order_by
  ).call
  @loaded = true
  self
end

#loaded?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/marquery/query.rb', line 67

def loaded?
  @loaded
end

#model(klass = nil) ⇒ Object



29
30
31
32
# File 'lib/marquery/query.rb', line 29

def model(klass = nil)
  @marquery_model = klass if klass
  @marquery_model
end

#order_by(field = nil, direction = nil) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/marquery/query.rb', line 39

def order_by(field = nil, direction = nil)
  if field
    @order_field = field.to_sym
    @order_direction = Marquery::Order.validate!(direction) if direction
  end
  [@order_field, @order_direction]
end

#reload!Object



83
84
85
86
87
# File 'lib/marquery/query.rb', line 83

def reload!
  @loaded = false
  @marquery_data = nil
  load!
end