Class: Kongfigure::Resources::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kongfigure/resources/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, kongfigure_ignore_fields = nil) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
15
# File 'lib/kongfigure/resources/base.rb', line 6

def initialize(id, kongfigure_ignore_fields = nil)
  @id                       = id
  @kongfigure_ignore_fields = (kongfigure_ignore_fields || []).map { |field| field.split(".") }
  if self.class != Kongfigure::Resources::Plugin && self.class != Kongfigure::Resources::Route
    @kongfigure_ignore_fields.push("id")
  end
  @plugins                  = []
  @updated                  = false
  @unchanged                = false
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/kongfigure/resources/base.rb', line 4

def id
  @id
end

#kongfigure_ignore_fieldsObject

Returns the value of attribute kongfigure_ignore_fields.



4
5
6
# File 'lib/kongfigure/resources/base.rb', line 4

def kongfigure_ignore_fields
  @kongfigure_ignore_fields
end

#pluginsObject

Returns the value of attribute plugins.



4
5
6
# File 'lib/kongfigure/resources/base.rb', line 4

def plugins
  @plugins
end

#unchangedObject

Returns the value of attribute unchanged.



4
5
6
# File 'lib/kongfigure/resources/base.rb', line 4

def unchanged
  @unchanged
end

#updatedObject

Returns the value of attribute updated.



4
5
6
# File 'lib/kongfigure/resources/base.rb', line 4

def updated
  @updated
end

Class Method Details

.build_all(resources_hash) ⇒ Object



21
22
23
24
25
# File 'lib/kongfigure/resources/base.rb', line 21

def self.build_all(resources_hash)
  resources_hash.map do |resource_hash|
    build(resource_hash)
  end
end

Instance Method Details

#==(other_object) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/kongfigure/resources/base.rb', line 27

def ==(other_object)
  differences       = deep_diff(other_object.api_attributes, api_attributes, kongfigure_ignore_fields)
  differences_count = differences.flatten.size
  if differences_count > 0
    ap api_attributes
    ap other_object.api_attributes
    ap differences
  end
  differences_count == 0
end

#api_nameObject

Raises:

  • (NotImplementedError)


54
55
56
# File 'lib/kongfigure/resources/base.rb', line 54

def api_name
  raise NotImplementedError
end

#display_nameObject



38
39
40
# File 'lib/kongfigure/resources/base.rb', line 38

def display_name
  identifier
end

#has_to_be_deleted?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/kongfigure/resources/base.rb', line 50

def has_to_be_deleted?
  @updated == false && @unchanged == false
end

#mark_as_unchangedObject



46
47
48
# File 'lib/kongfigure/resources/base.rb', line 46

def mark_as_unchanged
  @unchanged = true
end

#mark_as_updatedObject



42
43
44
# File 'lib/kongfigure/resources/base.rb', line 42

def mark_as_updated
  @updated = true
end

#plugin_allowed?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/kongfigure/resources/base.rb', line 17

def plugin_allowed?
  true
end