Class: Ey::Core::Model

Inherits:
Cistern::Model
  • Object
show all
Defined in:
lib/ey-core/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.range_parser(v) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ey-core/model.rb', line 15

def self.range_parser(v)
  case v
  when Range then
    v
  when String then
    first, last = v.split("-").map(&:to_i)
    last ||= first
    Range.new(first, last)
  else
    v
  end
end

Instance Method Details

#destroyObject



39
40
41
42
43
# File 'lib/ey-core/model.rb', line 39

def destroy
  destroy!
rescue Ey::Core::Response::Error
  false
end

#saveObject



33
34
35
36
37
# File 'lib/ey-core/model.rb', line 33

def save
  save!
rescue Ey::Core::Response::Error
  false
end

#to_sObject



10
11
12
13
# File 'lib/ey-core/model.rb', line 10

def to_s
  shortname = self.class.name.split("::").last
  "#{shortname}:#{id}"
end

#update!(attributes) ⇒ Object



28
29
30
31
# File 'lib/ey-core/model.rb', line 28

def update!(attributes)
  merge_attributes(attributes)
  save!
end

#urlObject



2
3
4
5
6
7
8
# File 'lib/ey-core/model.rb', line 2

def url
  if self.class.attributes[:url]
    read_attribute(:url)
  else
    "#{self.collection.url}/#{self.id}"
  end
end