Class: ApplicationType
- Inherits:
-
Object
- Object
- ApplicationType
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::MassAssignmentSecurity, RestApi::Cacheable
- Defined in:
- app/models/application_type.rb
Defined Under Namespace
Classes: NotFound
Constant Summary collapse
- PROTECTED_TAGS =
[:new, :premium, :blacklist, :featured]
- CartridgeSpecInvalid =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#cartridges ⇒ Object
Returns the value of attribute cartridges.
-
#cartridges_spec ⇒ Object
Returns the value of attribute cartridges_spec.
-
#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.
-
#id ⇒ Object
Returns the value of attribute id.
-
#initial_git_branch ⇒ Object
Returns the value of attribute initial_git_branch.
-
#initial_git_url ⇒ Object
Returns the value of attribute initial_git_url.
-
#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.
-
#scalable ⇒ Object
(also: #scalable?)
Returns the value of attribute scalable.
-
#source ⇒ Object
Returns the value of attribute source.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#version ⇒ Object
Returns the value of attribute version.
-
#website ⇒ Object
Returns the value of attribute website.
Class Method Summary collapse
- .all(*arguments) ⇒ Object
- .custom(attrs = {}) ⇒ Object
- .find(*arguments) ⇒ Object
- .matching_cartridges(cartridge_specs) ⇒ Object
- .search(query, opts = {}) ⇒ Object
- .tagged(tag, opts = {}) ⇒ Object
- .user_tags(tags) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #>>(app) ⇒ Object
-
#assign_attributes(values, options = {}) ⇒ Object
Default mass assignment support.
- #cartridge? ⇒ Boolean
- #cartridge_specs ⇒ Object
-
#initialize(attributes = {}, persisted = false) ⇒ ApplicationType
constructor
A new instance of ApplicationType.
- #matching_cartridges ⇒ Object
- #new? ⇒ Boolean
- #persisted? ⇒ Boolean
- #quickstart? ⇒ Boolean
- #source_priority ⇒ Object
- #to_params ⇒ Object
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ ApplicationType
Returns a new instance of ApplicationType.
33 34 35 36 37 38 |
# File 'app/models/application_type.rb', line 33 def initialize(attributes={}, persisted=false) attributes.each do |name,value| send("#{name}=", value) end @persisted = persisted end |
Instance Attribute Details
#cartridges ⇒ Object
Returns the value of attribute cartridges.
21 22 23 |
# File 'app/models/application_type.rb', line 21 def cartridges @cartridges end |
#cartridges_spec ⇒ Object
Returns the value of attribute cartridges_spec.
21 22 23 |
# File 'app/models/application_type.rb', line 21 def cartridges_spec @cartridges_spec end |
#description ⇒ Object
Returns the value of attribute description.
20 21 22 |
# File 'app/models/application_type.rb', line 20 def description @description end |
#display_name ⇒ Object
Returns the value of attribute display_name.
20 21 22 |
# File 'app/models/application_type.rb', line 20 def display_name @display_name end |
#help_topics ⇒ Object
Returns the value of attribute help_topics.
24 25 26 |
# File 'app/models/application_type.rb', line 24 def help_topics @help_topics end |
#id ⇒ Object
Returns the value of attribute id.
20 21 22 |
# File 'app/models/application_type.rb', line 20 def id @id end |
#initial_git_branch ⇒ Object
Returns the value of attribute initial_git_branch.
21 22 23 |
# File 'app/models/application_type.rb', line 21 def initial_git_branch @initial_git_branch end |
#initial_git_url ⇒ Object
Returns the value of attribute initial_git_url.
21 22 23 |
# File 'app/models/application_type.rb', line 21 def initial_git_url @initial_git_url end |
#learn_more_url ⇒ Object
Returns the value of attribute learn_more_url.
23 24 25 |
# File 'app/models/application_type.rb', line 23 def learn_more_url @learn_more_url end |
#license ⇒ Object
Returns the value of attribute license.
22 23 24 |
# File 'app/models/application_type.rb', line 22 def license @license end |
#license_url ⇒ Object
Returns the value of attribute license_url.
22 23 24 |
# File 'app/models/application_type.rb', line 22 def license_url @license_url end |
#priority ⇒ Object
Returns the value of attribute priority.
25 26 27 |
# File 'app/models/application_type.rb', line 25 def priority @priority end |
#scalable ⇒ Object Also known as: scalable?
Returns the value of attribute scalable.
26 27 28 |
# File 'app/models/application_type.rb', line 26 def scalable @scalable end |
#source ⇒ Object
Returns the value of attribute source.
28 29 30 |
# File 'app/models/application_type.rb', line 28 def source @source end |
#tags ⇒ Object
Returns the value of attribute tags.
23 24 25 |
# File 'app/models/application_type.rb', line 23 def @tags end |
#version ⇒ Object
Returns the value of attribute version.
20 21 22 |
# File 'app/models/application_type.rb', line 20 def version @version end |
#website ⇒ Object
Returns the value of attribute website.
22 23 24 |
# File 'app/models/application_type.rb', line 22 def website @website end |
Class Method Details
.all(*arguments) ⇒ Object
125 126 127 |
# File 'app/models/application_type.rb', line 125 def all(*arguments) find(:all, *arguments) end |
.custom(attrs = {}) ⇒ Object
163 164 165 166 167 |
# File 'app/models/application_type.rb', line 163 def custom(attrs={}) attrs = {} if attrs.nil? || attrs.is_a?(String) attrs[:scalable] = true unless attrs.has_key?(:scalable) new(:id => 'custom', :display_name => 'From Scratch').assign_attributes(attrs) end |
.find(*arguments) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/models/application_type.rb', line 137 def find(*arguments) option = arguments.shift case option when String find_single(option, *arguments) when :all find_every(*arguments) when Symbol find_every(*arguments).select { |t| t..include? option } else raise "Unsupported scope" end end |
.matching_cartridges(cartridge_specs) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/models/application_type.rb', line 151 def matching_cartridges(cartridge_specs) valid, invalid = {}, [] Array(cartridge_specs).uniq.each do |c| if (matches = CartridgeType.cached.matches(c)).present? valid[c] = matches else invalid << c end end [valid, invalid] end |
.search(query, opts = {}) ⇒ Object
129 130 131 |
# File 'app/models/application_type.rb', line 129 def search(query, opts={}) find(:all, {:search => query}.merge(opts)) end |
.tagged(tag, opts = {}) ⇒ Object
133 134 135 |
# File 'app/models/application_type.rb', line 133 def tagged(tag, opts={}) find(:all, {:tag => tag}.merge(opts)) end |
.user_tags(tags) ⇒ Object
8 9 10 |
# File 'app/models/application_type.rb', line 8 def self.() - PROTECTED_TAGS end |
Instance Method Details
#<=>(other) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'app/models/application_type.rb', line 74 def <=>(other) return 0 if id == other.id c = source_priority - other.source_priority return c unless c == 0 c = priority - other.priority return c unless c == 0 display_name <=> other.display_name end |
#>>(app) ⇒ Object
105 106 107 108 109 110 |
# File 'app/models/application_type.rb', line 105 def >>(app) app.cartridges = cartridges if cartridges.present? app.initial_git_url = initial_git_url if initial_git_url app.initial_git_branch = initial_git_branch if initial_git_branch app end |
#assign_attributes(values, options = {}) ⇒ Object
Default mass assignment support
115 116 117 118 119 120 |
# File 'app/models/application_type.rb', line 115 def assign_attributes(values, = {}) sanitize_for_mass_assignment(values, [:as]).each do |k, v| send("#{k}=", v) end self end |
#cartridge? ⇒ Boolean
98 |
# File 'app/models/application_type.rb', line 98 def cartridge?; source == :cartridge; end |
#cartridge_specs ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/application_type.rb', line 56 def cartridge_specs begin s = (@cartridges_spec || cartridges || []) if s.is_a? Array s else s = s.strip if s[0] == '[' ActiveSupport::JSON.decode(s).map{ |s| s.is_a?(Hash) ? s['name'] : s } else s.split(',').map(&:strip) end end rescue raise ApplicationType::CartridgeSpecInvalid, $!, $@ end end |
#matching_cartridges ⇒ Object
101 102 103 |
# File 'app/models/application_type.rb', line 101 def matching_cartridges self.class.matching_cartridges(cartridge_specs) end |
#new? ⇒ Boolean
44 45 46 |
# File 'app/models/application_type.rb', line 44 def new? .include?(:new) end |
#persisted? ⇒ Boolean
40 41 42 |
# File 'app/models/application_type.rb', line 40 def persisted? @persisted end |
#quickstart? ⇒ Boolean
99 |
# File 'app/models/application_type.rb', line 99 def quickstart?; source == :quickstart; end |
#source_priority ⇒ Object
91 92 93 94 95 96 |
# File 'app/models/application_type.rb', line 91 def source_priority case source when :cartridge; -2 else; 0 end end |
#to_params ⇒ Object
48 49 50 |
# File 'app/models/application_type.rb', line 48 def to_params persisted? ? {:id => id} : [:cartridges, :initial_git_url, :initial_git_branch].inject({}){ |h, s| h[s] = send(s); h } end |