Class: Blazer::Query

Inherits:
Record
  • Object
show all
Defined in:
app/models/blazer/query.rb

Instance Method Summary collapse

Instance Method Details

#cohort_analysis?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/blazer/query.rb', line 43

def cohort_analysis?
  /\/\*\s*cohort analysis\s*\*\//i.match?(statement)
end

#editable?(user) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'app/models/blazer/query.rb', line 30

def editable?(user)
  editable = !persisted? || (name.present? && name.first != "*" && name.first != "#") || user == try(:creator)
  editable &&= viewable?(user)
  editable &&= Blazer.query_editable.call(self, user) if Blazer.query_editable
  editable
end

#friendly_nameObject



18
19
20
# File 'app/models/blazer/query.rb', line 18

def friendly_name
  name.to_s.sub(/\A[#\*]/, "").gsub(/\[.+\]/, "").strip
end

#to_paramObject



14
15
16
# File 'app/models/blazer/query.rb', line 14

def to_param
  [id, name].compact.join("-").gsub("'", "").parameterize
end

#variablesObject



37
38
39
40
41
# File 'app/models/blazer/query.rb', line 37

def variables
  variables = Blazer.extract_vars(statement)
  variables += ["cohort_period"] if cohort_analysis?
  variables
end

#viewable?(user) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'app/models/blazer/query.rb', line 22

def viewable?(user)
  if Blazer.query_viewable
    Blazer.query_viewable.call(self, user)
  else
    true
  end
end