Class: CartridgeType

Inherits:
RestApi::Base show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, Comparable
Defined in:
app/models/cartridge_type.rb

Defined Under Namespace

Classes: Property

Instance Attribute Summary collapse

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, #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

#initialize(attributes = {}, persisted = false) ⇒ CartridgeType

Returns a new instance of CartridgeType.



29
30
31
32
33
34
35
36
# File 'app/models/cartridge_type.rb', line 29

def initialize(attributes={},persisted=false)
  attributes = attributes.with_indifferent_access
  name = attributes['name'].presence || attributes[:name].presence
  defaults = self.class.defaults(name)
  defaults.keys.each{ |k| attributes.delete(k) if attributes[k].blank? }
  attributes.reverse_merge!(defaults)
  super attributes, persisted
end

Dynamic Method Handling

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

Instance Attribute Details

#cartridgeObject

Returns the value of attribute cartridge.



18
19
20
# File 'app/models/cartridge_type.rb', line 18

def cartridge
  @cartridge
end

#conflictsObject

Returns the value of attribute conflicts.



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

def conflicts
  @conflicts
end

#descriptionObject

Returns the value of attribute description.



15
16
17
# File 'app/models/cartridge_type.rb', line 15

def description
  @description
end

#display_nameObject

Returns the value of attribute display_name.



16
17
18
# File 'app/models/cartridge_type.rb', line 16

def display_name
  @display_name
end

#help_topicsObject

Returns the value of attribute help_topics.



22
23
24
# File 'app/models/cartridge_type.rb', line 22

def help_topics
  @help_topics
end

#learn_more_urlObject

Returns the value of attribute learn_more_url.



20
21
22
# File 'app/models/cartridge_type.rb', line 20

def learn_more_url
  @learn_more_url
end

#licenseObject

Returns the value of attribute license.



19
20
21
# File 'app/models/cartridge_type.rb', line 19

def license
  @license
end

#license_urlObject

Returns the value of attribute license_url.



19
20
21
# File 'app/models/cartridge_type.rb', line 19

def license_url
  @license_url
end

#priorityObject

Returns the value of attribute priority.



23
24
25
# File 'app/models/cartridge_type.rb', line 23

def priority
  @priority
end

#providesObject

Returns the value of attribute provides.



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

def provides
  @provides
end

#requiresObject

Returns the value of attribute requires.



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

def requires
  @requires
end

#versionObject

Returns the value of attribute version.



15
16
17
# File 'app/models/cartridge_type.rb', line 15

def version
  @version
end

#websiteObject

Returns the value of attribute website.



19
20
21
# File 'app/models/cartridge_type.rb', line 19

def website
  @website
end

Class Method Details

.embedded(*arguments) ⇒ Object



95
96
97
# File 'app/models/cartridge_type.rb', line 95

def self.embedded(*arguments)
  all(*arguments).select(&:embedded?)
end

.matches(s, opts = nil) ⇒ Object



103
104
105
106
107
108
109
110
# File 'app/models/cartridge_type.rb', line 103

def self.matches(s, opts=nil)
  every = all(opts)
  s.split('|').map{ |s| s.gsub('*','') }.map do |s|
    Array(every.find{ |t| t.name == s } || every.select do |t| 
      t.name.include?(s) 
    end)
  end.flatten.uniq
end

.standalone(*arguments) ⇒ Object



99
100
101
# File 'app/models/cartridge_type.rb', line 99

def self.standalone(*arguments)
  all(*arguments).select(&:standalone?)
end

.tag_compare(a, b) ⇒ Object



114
115
116
117
118
119
120
121
122
123
# File 'app/models/cartridge_type.rb', line 114

def self.tag_compare(a,b)
  [:web_framework, :database].each do |t|
    if a.include? t
      return -1 unless b.include? t
    else
      return 1 if b.include? t
    end
  end
  0
end

Instance Method Details

#<=>(other) ⇒ Object



86
87
88
89
90
91
92
93
# File 'app/models/cartridge_type.rb', line 86

def <=>(other)
  return 0 if name == other.name
  c = self.class.tag_compare(tags, other.tags)
  return c unless c == 0
  c = priority - other.priority
  return c unless c == 0
  display_name <=> other.display_name
end

#categoriesObject

Legacy, use #tags



50
51
52
# File 'app/models/cartridge_type.rb', line 50

def categories
  @categories || []
end

#categories=(cats) ⇒ Object



53
54
55
# File 'app/models/cartridge_type.rb', line 53

def categories=(cats)
  @categories = cats.map{ |c| c.to_sym }.compact.uniq
end

#embedded?Boolean

Returns:

  • (Boolean)


42
# File 'app/models/cartridge_type.rb', line 42

def embedded?;    type == :embedded; end

#scalableObject Also known as: scalable?



81
82
83
# File 'app/models/cartridge_type.rb', line 81

def scalable
  self.attributes['supported_scales_to'] != self.attributes['supported_scales_from']
end

#standalone?Boolean

Returns:

  • (Boolean)


43
# File 'app/models/cartridge_type.rb', line 43

def standalone?;  type == :standalone; end

#tagsObject



57
58
59
# File 'app/models/cartridge_type.rb', line 57

def tags
  @tags ||= (super || [] rescue []).map{ |t| t.to_sym}.concat(categories).compact
end

#tags=(tags) ⇒ Object



60
61
62
63
# File 'app/models/cartridge_type.rb', line 60

def tags=(tags)
  @tags = nil
  @attributes[:tags] = tags
end

#typeObject



38
39
40
# File 'app/models/cartridge_type.rb', line 38

def type
  (@attributes[:type] || :embedded).to_sym
end