Module: Machinery::Scope

Defined in:
lib/scope.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#metaObject

Returns the value of attribute meta.



80
81
82
# File 'lib/scope.rb', line 80

def meta
  @meta
end

#scope_file_storeObject

Returns the value of attribute scope_file_store.



81
82
83
# File 'lib/scope.rb', line 81

def scope_file_store
  @scope_file_store
end

Class Method Details

.all_scopesObject



27
28
29
# File 'lib/scope.rb', line 27

def self.all_scopes
  @scopes
end

.extract_changed_elements(a, b, primary_key) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/scope.rb', line 49

def self.extract_changed_elements(a, b, primary_key)
  changed_keys = a.map(&primary_key) & b.map(&primary_key)
  changed = []

  changed_keys.each do |key|
    changed << [
      a.find { |e| e.send(primary_key) == key },
      b.find { |e| e.send(primary_key) == key },
    ]
    a.reject! { |e| e.send(primary_key) == key }
    b.reject! { |e| e.send(primary_key) == key }
  end

  changed
end

.for(scope_name, json, scope_file_store) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scope.rb', line 35

def self.for(scope_name, json, scope_file_store)
  all_scopes.each do |scope|
    if scope.new.scope_name == scope_name
      scope = scope.from_json(json)
      scope.scope_file_store = scope_file_store

      scope.scope = scope

      return scope
    end
  end
  nil
end

.included(mod) ⇒ Object



20
21
22
23
24
25
# File 'lib/scope.rb', line 20

def self.included(mod)
  mod.extend(ClassMethods)

  @scopes ||= []
  @scopes.push(mod)
end

.visible_scopesObject



31
32
33
# File 'lib/scope.rb', line 31

def self.visible_scopes
  all_scopes.reject(&:hidden?)
end

Instance Method Details

#is_extractable?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/scope.rb', line 94

def is_extractable?
  Machinery::SystemDescription::EXTRACTABLE_SCOPES.include?(scope_name)
end

#scope_nameObject



90
91
92
# File 'lib/scope.rb', line 90

def scope_name
  self.class.scope_name
end

#set_metadata(timestring, host) ⇒ Object



83
84
85
86
87
88
# File 'lib/scope.rb', line 83

def (timestring, host)
  self.meta = Machinery::Object.new(
    modified: timestring,
    hostname: host
  )
end