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.
-
#template ⇒ Object
DEPRECATED.
-
#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
- #template? ⇒ Boolean
- #to_params ⇒ Object
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ ApplicationType
Returns a new instance of ApplicationType.
34 35 36 37 38 39 |
# File 'app/models/application_type.rb', line 34 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.
25 26 27 |
# File 'app/models/application_type.rb', line 25 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.
24 25 26 |
# File 'app/models/application_type.rb', line 24 def learn_more_url @learn_more_url end |
#license ⇒ Object
Returns the value of attribute license.
23 24 25 |
# File 'app/models/application_type.rb', line 23 def license @license end |
#license_url ⇒ Object
Returns the value of attribute license_url.
23 24 25 |
# File 'app/models/application_type.rb', line 23 def license_url @license_url end |
#priority ⇒ Object
Returns the value of attribute priority.
26 27 28 |
# File 'app/models/application_type.rb', line 26 def priority @priority end |
#scalable ⇒ Object Also known as: scalable?
Returns the value of attribute scalable.
27 28 29 |
# File 'app/models/application_type.rb', line 27 def scalable @scalable end |
#source ⇒ Object
Returns the value of attribute source.
29 30 31 |
# File 'app/models/application_type.rb', line 29 def source @source end |
#tags ⇒ Object
Returns the value of attribute tags.
24 25 26 |
# File 'app/models/application_type.rb', line 24 def end |
#template ⇒ Object
DEPRECATED
22 23 24 |
# File 'app/models/application_type.rb', line 22 def template @template 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.
23 24 25 |
# File 'app/models/application_type.rb', line 23 def website @website end |
Class Method Details
.all(*arguments) ⇒ Object
132 133 134 |
# File 'app/models/application_type.rb', line 132 def all(*arguments) find(:all, *arguments) end |
.custom(attrs = {}) ⇒ Object
170 171 172 173 174 |
# File 'app/models/application_type.rb', line 170 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
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/models/application_type.rb', line 144 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
158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/models/application_type.rb', line 158 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
136 137 138 |
# File 'app/models/application_type.rb', line 136 def search(query, opts={}) find(:all, {:search => query}.merge(opts)) end |
.tagged(tag, opts = {}) ⇒ Object
140 141 142 |
# File 'app/models/application_type.rb', line 140 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
75 76 77 78 79 80 81 82 |
# File 'app/models/application_type.rb', line 75 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
108 109 110 111 112 113 114 115 116 117 |
# File 'app/models/application_type.rb', line 108 def >>(app) if template app.template = template.uuid else 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 end app end |
#assign_attributes(values, options = {}) ⇒ Object
Default mass assignment support
122 123 124 125 126 127 |
# File 'app/models/application_type.rb', line 122 def assign_attributes(values, = {}) sanitize_for_mass_assignment(values, [:as]).each do |k, v| send("#{k}=", v) end self end |
#cartridge? ⇒ Boolean
100 |
# File 'app/models/application_type.rb', line 100 def cartridge?; source == :cartridge; end |
#cartridge_specs ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/application_type.rb', line 57 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
104 105 106 |
# File 'app/models/application_type.rb', line 104 def matching_cartridges self.class.matching_cartridges(cartridge_specs) end |
#new? ⇒ Boolean
45 46 47 |
# File 'app/models/application_type.rb', line 45 def new? .include?(:new) end |
#persisted? ⇒ Boolean
41 42 43 |
# File 'app/models/application_type.rb', line 41 def persisted? @persisted end |
#quickstart? ⇒ Boolean
102 |
# File 'app/models/application_type.rb', line 102 def quickstart?; source == :quickstart; end |
#source_priority ⇒ Object
92 93 94 95 96 97 98 |
# File 'app/models/application_type.rb', line 92 def source_priority case source when :template; -1 when :cartridge; -2 else; 0 end end |
#template? ⇒ Boolean
101 |
# File 'app/models/application_type.rb', line 101 def template?; source == :template; end |
#to_params ⇒ Object
49 50 51 |
# File 'app/models/application_type.rb', line 49 def to_params persisted? ? {:id => id} : [:cartridges, :initial_git_url, :initial_git_branch].inject({}){ |h, s| h[s] = send(s); h } end |