Class: CartridgeType
- Inherits:
-
RestApi::Base
- Object
- ActiveResource::Base
- RestApi::Base
- CartridgeType
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, Comparable
- Defined in:
- app/models/cartridge_type.rb
Defined Under Namespace
Classes: Property
Instance Attribute Summary collapse
-
#cartridge ⇒ Object
Returns the value of attribute cartridge.
-
#conflicts ⇒ Object
Returns the value of attribute conflicts.
-
#description ⇒ Object
Returns the value of attribute description.
-
#display_name ⇒ Object
Returns the value of attribute display_name.
-
#help_topics ⇒ Object
Returns the value of attribute help_topics.
-
#learn_more_url ⇒ Object
Returns the value of attribute learn_more_url.
-
#license ⇒ Object
Returns the value of attribute license.
-
#license_url ⇒ Object
Returns the value of attribute license_url.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#provides ⇒ Object
Returns the value of attribute provides.
-
#requires ⇒ Object
Returns the value of attribute requires.
-
#version ⇒ Object
Returns the value of attribute version.
-
#website ⇒ Object
Returns the value of attribute website.
Class Method Summary collapse
- .embedded(*arguments) ⇒ Object
- .matches(s, opts = nil) ⇒ Object
- .standalone(*arguments) ⇒ Object
- .tag_compare(a, b) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#categories ⇒ Object
Legacy, use #tags.
- #categories=(cats) ⇒ Object
- #embedded? ⇒ Boolean
-
#initialize(attributes = {}, persisted = false) ⇒ CartridgeType
constructor
A new instance of CartridgeType.
- #scalable ⇒ Object (also: #scalable?)
- #standalone? ⇒ Boolean
- #tags ⇒ Object
- #tags=(tags) ⇒ Object
- #type ⇒ Object
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
#cartridge ⇒ Object
Returns the value of attribute cartridge.
18 19 20 |
# File 'app/models/cartridge_type.rb', line 18 def cartridge @cartridge end |
#conflicts ⇒ Object
Returns the value of attribute conflicts.
21 22 23 |
# File 'app/models/cartridge_type.rb', line 21 def conflicts @conflicts end |
#description ⇒ Object
Returns the value of attribute description.
15 16 17 |
# File 'app/models/cartridge_type.rb', line 15 def description @description end |
#display_name ⇒ Object
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_topics ⇒ Object
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_url ⇒ Object
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 |
#license ⇒ Object
Returns the value of attribute license.
19 20 21 |
# File 'app/models/cartridge_type.rb', line 19 def license @license end |
#license_url ⇒ Object
Returns the value of attribute license_url.
19 20 21 |
# File 'app/models/cartridge_type.rb', line 19 def license_url @license_url end |
#priority ⇒ Object
Returns the value of attribute priority.
23 24 25 |
# File 'app/models/cartridge_type.rb', line 23 def priority @priority end |
#provides ⇒ Object
Returns the value of attribute provides.
17 18 19 |
# File 'app/models/cartridge_type.rb', line 17 def provides @provides end |
#requires ⇒ Object
Returns the value of attribute requires.
21 22 23 |
# File 'app/models/cartridge_type.rb', line 21 def requires @requires end |
#version ⇒ Object
Returns the value of attribute version.
15 16 17 |
# File 'app/models/cartridge_type.rb', line 15 def version @version end |
#website ⇒ Object
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.(*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(, other.) return c unless c == 0 c = priority - other.priority return c unless c == 0 display_name <=> other.display_name end |
#categories ⇒ Object
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
42 |
# File 'app/models/cartridge_type.rb', line 42 def ; type == :embedded; end |
#scalable ⇒ Object 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
43 |
# File 'app/models/cartridge_type.rb', line 43 def standalone?; type == :standalone; end |
#tags ⇒ Object
57 58 59 |
# File 'app/models/cartridge_type.rb', line 57 def @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 = nil @attributes[:tags] = end |
#type ⇒ Object
38 39 40 |
# File 'app/models/cartridge_type.rb', line 38 def type (@attributes[:type] || :embedded).to_sym end |