Class: PuppetX::Puppetlabs::Migration::OverviewModel::Query::Wrapper Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/puppetlabs/migration/overview_model/query.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wraps an Entity and gives it the ability to navigate its relationships as they were normal attributes of the class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(overview, entity) ⇒ Wrapper

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new wrapper for the given entity that uses the given overview to lookup its id references

Parameters:

  • overview (#raw_of_class, #[])

    the overview used for lookups

  • entity (Entity)

    the entity to wrap

Raises:

  • (ArgumentError)


55
56
57
58
59
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 55

def initialize(overview, entity)
  @overview = overview
  raise ArgumentError unless entity.is_a?(Entity)
  @entity = entity
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



93
94
95
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 93

def method_missing(name, *args)
  args.empty? ? dispatch(name) : super
end

Instance Attribute Details

#entityObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 47

def entity
  @entity
end

Instance Method Details

#<=>(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 69

def <=>(other)
  other.is_a?(Wrapper) ? @entity <=> other.entity : nil
end

#==(other) ⇒ Object Also known as: eql?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 73

def ==(other)
  self.class.equal?(other.class) && @entity.equal?(other.entity)
end

#dispatch(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 101

def dispatch(name)
  if many = @entity.many_relationship(name)
    result = resolve_next(@entity, many)
    if is_scalar(many)
      result.nil? ? nil : Wrapper.new(@overview, result)
    else
      if result.is_a?(Array)
        WrappingArray.from_entities(@overview, result)
      else
        EMPTY_ARRAY
      end
    end
  elsif one = @entity.one_relationship(name)
    one == UNDEFINED_ID ? nil : Wrapper.new(@overview, @overview[one])
  else
    @entity.send(name)
  end
end

#exit_codeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clobbered by test framework unless present (adding respond_to_missing? doesn’t help)



89
90
91
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 89

def exit_code
  @entity.exit_code
end

#hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 65

def hash
  @entity.hash
end

#idObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 61

def id
  @entity.id
end

#is_scalar(relationship) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 79

def is_scalar(relationship)
  relationship.is_a?(Array) && relationship.last.is_a?(ScalarValue)
end

#messageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clobbered by test framework unless present (adding respond_to_missing? doesn’t help)



84
85
86
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 84

def message
  dispatch(:message)
end

#resolve_next(base, nxt) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 120

def resolve_next(base, nxt)
  if base.is_a?(Array)
    result = base.map { |entity| resolve_next(entity, nxt) }
    result.compact!
    result
  else
    case nxt
    when Symbol
      id = base.send(nxt)
      id.nil? ? nil : @overview[id]
    when RelationalStep
      nxt.evaluate(base)
    when Array
      nxt.inject(base) do |entity, n|
        break nil if entity.nil?
        resolve_next(entity, n)
      end
    when UnboundMethod
      id = base.id
      @overview.raw_of_class(nxt.owner).select { |entity| nxt.bind(entity).call == id }
    else
      nil
    end
  end
end

#respond_to_missing?(name, include_private) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


97
98
99
# File 'lib/puppet_x/puppetlabs/migration/overview_model/query.rb', line 97

def respond_to_missing?(name, include_private)
  !(@entity.many_relationship(name).nil? && @entity.one_relationship(name).nil? && !@entity.respond_to?(name))
end