Module: ActiveShotgun::Model::Read::ClassMethods

Defined in:
lib/active_shotgun/model/read.rb

Instance Method Summary collapse

Instance Method Details

#allObject



36
37
38
# File 'lib/active_shotgun/model/read.rb', line 36

def all
  prepare_new_query.all
end

#countObject



73
74
75
# File 'lib/active_shotgun/model/read.rb', line 73

def count
  prepare_new_query.count
end

#find(id) ⇒ Object



68
69
70
71
# File 'lib/active_shotgun/model/read.rb', line 68

def find(id)
  sg_result = shotgun_client.find(id)
  parse_shotgun_results(sg_result)
end

#find_by(conditions) ⇒ Object



56
57
58
# File 'lib/active_shotgun/model/read.rb', line 56

def find_by(conditions)
  prepare_new_query.find_by(conditions)
end

#first(number = 1) ⇒ Object



48
49
50
# File 'lib/active_shotgun/model/read.rb', line 48

def first(number = 1)
  prepare_new_query.first(number)
end

#limit(number) ⇒ Object



40
41
42
# File 'lib/active_shotgun/model/read.rb', line 40

def limit(number)
  prepare_new_query.limit(number)
end

#offset(number) ⇒ Object



44
45
46
# File 'lib/active_shotgun/model/read.rb', line 44

def offset(number)
  prepare_new_query.limit(number)
end

#orders(new_orders) ⇒ Object



60
61
62
# File 'lib/active_shotgun/model/read.rb', line 60

def orders(new_orders)
  prepare_new_query.orders(new_orders)
end

#parse_shotgun_results(sg_result) ⇒ Object



81
82
83
84
85
86
# File 'lib/active_shotgun/model/read.rb', line 81

def parse_shotgun_results(sg_result)
  new(
    sg_result.attributes.to_h.merge(id: sg_result.id),
    sg_result.relationships.transform_values{ |v| v["data"] }.with_indifferent_access
  )
end

#prepare_new_queryObject



64
65
66
# File 'lib/active_shotgun/model/read.rb', line 64

def prepare_new_query
  Query.new(type: shotgun_type, klass: self)
end

#sizeObject



77
78
79
# File 'lib/active_shotgun/model/read.rb', line 77

def size
  prepare_new_query.size
end

#where(conditions) ⇒ Object



52
53
54
# File 'lib/active_shotgun/model/read.rb', line 52

def where(conditions)
  prepare_new_query.where(conditions)
end