Class: Copy::Base

Inherits:
Object
  • Object
show all
Includes:
Operations::Base
Defined in:
lib/copy/base.rb

Direct Known Subclasses

File, Link, Revision, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Operations::Base

included

Constructor Details

#initialize(attributes = {}) ⇒ Base

Initializes the object using the given attributes

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes to use for initialization



10
11
12
13
# File 'lib/copy/base.rb', line 10

def initialize(attributes = {})
  set_attributes(attributes)
  parse_timestamps
end

Instance Attribute Details

#created_timeObject

Returns the value of attribute created_time.



5
6
7
# File 'lib/copy/base.rb', line 5

def created_time
  @created_time
end

Instance Method Details

#errorsObject

Accesor for the errors



24
25
26
# File 'lib/copy/base.rb', line 24

def errors
  @errors || []
end

#parse_timestampsObject

Parses UNIX timestamps and creates Time objects.



38
39
40
41
# File 'lib/copy/base.rb', line 38

def parse_timestamps
  @created_time = created_time.to_i if created_time.is_a? String
  @created_time = Time.at(created_time) if created_time
end

#set_attributes(attributes) ⇒ Object

Sets the attributes

Parameters:

  • attributes (Hash)

    The attributes to initialize



31
32
33
34
35
# File 'lib/copy/base.rb', line 31

def set_attributes(attributes)
  attributes.each_pair do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

#valid?Boolean

Model validations

Returns:

  • (Boolean)


18
19
20
# File 'lib/copy/base.rb', line 18

def valid?
  self.errors.empty?
end