Class: KakaxiParse::Farm

Inherits:
BaseModel show all
Defined in:
lib/kakaxi_parse/farm.rb

Constant Summary collapse

@@belongs_to =
[User]

Constants inherited from BaseModel

BaseModel::DEFUALT_LIMIT

Instance Attribute Summary collapse

Attributes inherited from BaseModel

#created_at, #id, #name, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

all, #delete, demodulize, find, order

Constructor Details

#initialize(id: nil, name: nil, farmer_id: nil, location: nil, updated_at: nil, created_at: nil) ⇒ Farm

Returns a new instance of Farm.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/kakaxi_parse/farm.rb', line 6

def initialize(
      id: nil,
      name: nil,
      farmer_id: nil,
      location:  nil,
      updated_at: nil,
      created_at: nil
    )
  @farmer_id = farmer_id
  @location  = location
  super(id, name, updated_at, created_at)
end

Instance Attribute Details

#farmer_idObject

Returns the value of attribute farmer_id.



3
4
5
# File 'lib/kakaxi_parse/farm.rb', line 3

def farmer_id
  @farmer_id
end

#locationObject

Returns the value of attribute location.



3
4
5
# File 'lib/kakaxi_parse/farm.rb', line 3

def location
  @location
end

Class Method Details

.short_nameObject



23
24
25
# File 'lib/kakaxi_parse/farm.rb', line 23

def self.short_name
  'farm'
end

.where(hash, limit: DEFUALT_LIMIT) ⇒ Object



19
20
21
# File 'lib/kakaxi_parse/farm.rb', line 19

def self.where(hash, limit: DEFUALT_LIMIT)
  to_objects(super(self, hash, limit, @@belongs_to)) if valid_key?(hash)
end

Instance Method Details

#devicesObject



45
46
47
# File 'lib/kakaxi_parse/farm.rb', line 45

def devices
  KakaxiDevice.where(farm_id: id)
end

#farmerObject



41
42
43
# File 'lib/kakaxi_parse/farm.rb', line 41

def farmer
  User.find(farmer_id)
end

#saveObject



27
28
29
# File 'lib/kakaxi_parse/farm.rb', line 27

def save
  id ? false : super(self, { name: name, farmer_id: farmer_id }, @@belongs_to)
end

#update(params) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/kakaxi_parse/farm.rb', line 31

def update(params)
  original_params = build_original_params(params)
  if super(self, params, @@belongs_to)
    original_params.each { |key, value| self.send("#{key}=", value) }
    true
  else
    false
  end
end