Class: GearGroup

Inherits:
RestApi::Base show all
Defined in:
app/models/gear_group.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestApi::Base

alias_attribute, aliased_attributes, allow_anonymous?, #as, #as=, #assign_attributes, attr_alters, #attributes=, calculated_attributes, #clone, configuration=, connection, custom_id, delete, #dup, #duplicate_errors, element_path, exception_for_code, find, find_one, get, #get, #has_exit_code?, headers, #initialize, #load, #load_remote_errors, on_exit_code, #raise_on_invalid, #reload, remote_errors_for, #remote_results, #save!, #save_with_change_tracking, shared_connection, singleton?, #to_json, translate_api_error, use_patch_on_update?, #valid?

Methods included from ActiveResource::Associations

#belongs_to, #has_many, #has_one

Constructor Details

This class inherits a constructor from RestApi::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RestApi::Base

Class Method Details

.infer(cartridges, application) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/gear_group.rb', line 69

def self.infer(cartridges, application)
  groups = cartridges.group_by(&:grouping).map do |a|
    GearGroup.new({
      :cartridges => a[1].sort!, 
      :gear_profile => a[1].first.gear_profile
    }, true)
  end
  groups.delete_if{ |g| g.send(:move_features, groups[0]) }
  groups.sort!{ |a,b| a.cartridges.first <=> b.cartridges.first }

  if groups.first
    cart = groups.first.cartridges.first
    cart.git_url = application.git_url
    cart.ssh_url = application.ssh_url
    cart.ssh_string = application.ssh_string
  end
  groups
end

Instance Method Details

#==(other) ⇒ Object



59
60
61
# File 'app/models/gear_group.rb', line 59

def ==(other)
  super && other.gears == gears && other.cartridges == cartridges
end

#builds?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/gear_group.rb', line 47

def builds?
  @builds
end

#cartridge_namesObject



40
41
42
# File 'app/models/gear_group.rb', line 40

def cartridge_names
  exposes.keys
end

#cartridgesObject



17
18
19
# File 'app/models/gear_group.rb', line 17

def cartridges
  @attributes['cartridges'] ||= []
end

#exposesObject



29
30
31
# File 'app/models/gear_group.rb', line 29

def exposes
  @exposes ||= cartridges.inject({}) { |h, c| h[c.name] = c; h }
end

#exposes?(cart = nil, &block) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'app/models/gear_group.rb', line 32

def exposes?(cart=nil, &block)
  if cart
    exposes.has_key? cart
  elsif block_given?
    cartridges.any? &block
  end
end

#gear_profileObject



21
22
23
# File 'app/models/gear_group.rb', line 21

def gear_profile
  (@attributes['gear_profile'] || :small).to_sym
end

#gearsObject



14
15
16
# File 'app/models/gear_group.rb', line 14

def gears
  @attributes['gears'] ||= []
end

#merge_gears(others) ⇒ Object



63
64
65
66
67
# File 'app/models/gear_group.rb', line 63

def merge_gears(others)
  Array(others).select{ |o| !(cartridges & o.cartridges).empty? }.each{ |o| gears.concat(o.gears) }
  gears.uniq!
  self
end

#scales?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/gear_group.rb', line 44

def scales?
  supported_scales_to != supported_scales_from
end

#statesObject



25
26
27
# File 'app/models/gear_group.rb', line 25

def states
  gears.map{ |g| g.state }
end

#supported_scales_fromObject



51
52
53
# File 'app/models/gear_group.rb', line 51

def supported_scales_from
  super || 1
end

#supported_scales_toObject



55
56
57
# File 'app/models/gear_group.rb', line 55

def supported_scales_to
  super || -1
end