Class: RubySync::Operation

Inherits:
Object show all
Includes:
Utilities
Defined in:
lib/ruby_sync/operation.rb

Overview

Operations that may be performed on an attribute

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#as_array, #call_if_exists, #class_called, #class_for_name, #class_name_for, #connector_called, #dump_after, #dump_before, #effective_operations, #ensure_dir_exists, #get_preference, #get_preference_file_path, #include_in_search_path, #log_progress, #perform_operations, #perform_transform, #pipeline_called, #set_preference, #something_called, #with_rescue

Constructor Details

#initialize(type, subject, values) ⇒ Operation

Returns a new instance of Operation.



39
40
41
42
43
# File 'lib/ruby_sync/operation.rb', line 39

def initialize type, subject, values
  self.type = type.to_sym
  self.subject = subject.to_s
  self.values = values
end

Instance Attribute Details

#subjectObject

Returns the value of attribute subject.



23
24
25
# File 'lib/ruby_sync/operation.rb', line 23

def subject
  @subject
end

#typeObject

Returns the value of attribute type.



23
24
25
# File 'lib/ruby_sync/operation.rb', line 23

def type
  @type
end

#valuesObject

Returns the value of attribute values.



23
24
25
# File 'lib/ruby_sync/operation.rb', line 23

def values
  @values
end

Class Method Details

.add(subject, values) ⇒ Object



26
27
28
# File 'lib/ruby_sync/operation.rb', line 26

def self.add subject, values
  self.new(:add, subject, values)
end

.delete(subject, values = nil) ⇒ Object



30
31
32
# File 'lib/ruby_sync/operation.rb', line 30

def self.delete subject, values=nil
  self.new(:delete, subject, values)
end

.replace(subject, values) ⇒ Object



34
35
36
# File 'lib/ruby_sync/operation.rb', line 34

def self.replace subject, values
  self.new(:replace, subject, values)
end

Instance Method Details

#==(o) ⇒ Object



45
46
47
48
49
# File 'lib/ruby_sync/operation.rb', line 45

def ==(o)
  subject == o.subject &&
  type == o.type &&
  values == o.values
end

#same_but_as(type) ⇒ Object

Returns a duplicate of this operation but with the type changed to the specified type



82
83
84
85
86
87
# File 'lib/ruby_sync/operation.rb', line 82

def same_but_as type
  op = self.dup
  op.type = type
  op.values = nil if type == :delete
  op
end

#same_but_on(subject) ⇒ Object

Returns a duplicate of this operation but with the subject changed to the specified subject



74
75
76
77
78
# File 'lib/ruby_sync/operation.rb', line 74

def same_but_on subject
  op = self.dup
  op.subject = subject
  op
end

#same_but_with(values) ⇒ Object

Returns a duplicate of this operation but with the values changed to those specified



91
92
93
94
95
# File 'lib/ruby_sync/operation.rb', line 91

def same_but_with values
  op = self.dub
  op.values = values
  op
end

#sets_blank?Boolean

Returns:

  • (Boolean)


97
98
99
100
# File 'lib/ruby_sync/operation.rb', line 97

def sets_blank?
  [:add, :replace].include? @type and
  (!@values || as_array(@values).select {|v| v && v != ''}.empty?)
end

#valueObject



64
65
66
# File 'lib/ruby_sync/operation.rb', line 64

def value
  @values and @values[0]
end

#value=(new_value) ⇒ Object



68
69
70
# File 'lib/ruby_sync/operation.rb', line 68

def value= new_value
  @values = new_value.as_array
end