Module: ActsAsCloudhdr
- Defined in:
- lib/cloudhdr_rails/errors.rb,
lib/cloudhdr_rails/acts_as_cloudhdr.rb
Defined Under Namespace
Modules: InstanceMethods Classes: Error, HTTPError, ThumbnailAttributesNotFoundError, ThumbnailNotFoundError
Class Method Summary collapse
- .apply_cloudhdr_configuration ⇒ Object
- .cloudhdr_config ⇒ Object
- .cloudhdr_configuration ⇒ Object
- .read_cloudhdr_configuration ⇒ Object
Instance Method Summary collapse
- #acts_as_cloudhdr(options = { }) ⇒ Object
- #create_atts_from_size_string(label_string) ⇒ Object
- #create_label_from_size_string(size_string) ⇒ Object
- #image?(content_type) ⇒ Boolean
-
#image_types ⇒ Object
The list of content types that will trigger image handling.
- #thumbnail_attributes_for(thumbnail_name = "small") ⇒ Object
- #update_from_cloudhdr(params) ⇒ Object
-
#validates_cloudhdr ⇒ Object
end.
- #web_safe?(content_type) ⇒ Boolean
Class Method Details
.apply_cloudhdr_configuration ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 285 def self.apply_cloudhdr_configuration if self.cloudhdr_configuration[:base_url] ActsAsCloudhdr.base_url = cloudhdr_configuration[:base_url] end if self.cloudhdr_configuration[:storeage_mode] ActsAsCloudhdr.storeage_mode = cloudhdr_configuration[:storeage_mode] end if self.cloudhdr_configuration[:processing_mode] ActsAsCloudhdr.processing_mode = cloudhdr_configuration[:processing_mode] end if self.cloudhdr_configuration[:s3_bucket_name] ActsAsCloudhdr.s3_bucket_name = cloudhdr_configuration[:s3_bucket_name] end if self.cloudhdr_configuration[:javascript_library] ActsAsCloudhdr.javascript_library = cloudhdr_configuration[:javascript_library] end if self.cloudhdr_configuration[:local_base_dir] ActsAsCloudhdr.local_base_dir = cloudhdr_configuration[:local_base_dir] end if self.cloudhdr_configuration[:cloudhdr_url] ::Cloudhdr.base_url = cloudhdr_configuration[:cloudhdr_url] end if self.cloudhdr_configuration[:cloudhdr_api_key] ::Cloudhdr.api_key = cloudhdr_configuration[:cloudhdr_api_key] end end |
.cloudhdr_config ⇒ Object
63 64 65 66 67 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 63 def self.cloudhdr_config #puts "checking cloudhdr_config for #{self.config}" self.read_cloudhdr_configuration if self.config.nil? self.config end |
.cloudhdr_configuration ⇒ Object
281 282 283 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 281 def self.cloudhdr_configuration self.config end |
.read_cloudhdr_configuration ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 69 def self.read_cloudhdr_configuration config_path = File.join(::Rails.root.to_s, ActsAsCloudhdr.config_file) #puts "#{self.config} - looking for a config in #{config_path}" self.config = YAML.load(ERB.new(File.read(config_path)).result)[::Rails.env.to_s].symbolize_keys self.apply_cloudhdr_configuration end |
Instance Method Details
#acts_as_cloudhdr(options = { }) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 151 def acts_as_cloudhdr( = { }) include InstanceMethods attr_reader :saved_file attr_accessor :processing after_save :save_local_file before_destroy :cleanup #:remove_local_file,:destroy_thumbnails,:remove_s3_file include ActiveSupport::Callbacks define_callbacks :local_file_saved, :file_saved, :file_ready, :process_hdr, :process_hdrhtml, :process_composite, :process_tone_mapping #cattr_accessor :cloudhdr_options #self.cloudhdr_options = options cattr_accessor :cloudhdr_thumbnails self.cloudhdr_thumbnails = [:thumbnails] ||= [] cattr_accessor :thumbnail_class self.thumbnail_class = [:thumbnail_class] ? [:thumbnail_class].constantize : self has_many :thumbnails, :class_name => "::#{self.thumbnail_class.name}",:as => :parent belongs_to :parent, :polymorphic => true has_many :cloudhdr_jobs, :as => :image scope :top_level, -> { where({:parent_id=>nil}) if respond_to?(:parent_id) } scope :top_level, -> { where({}) if !respond_to?(:parent_id) } # we can't just call this next scope 'parents' because that is already # taken and returns an array of parent classes of the ruby object scope :parent_items, -> { where({:parent_id=>nil}) if respond_to?(:parent_id) } scope :parent_items, -> { where({}) if !respond_to?(:parent_id) } scope :thumbnails, -> { where("#{base_class.table_name}.parent_id is not null") } #just a writer, the reader is below #cattr_accessor :cloudhdr_configuration #read_cloudhdr_configuration end |
#create_atts_from_size_string(label_string) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 251 def create_atts_from_size_string(label_string) match = label_string.match ActsAsCloudhdr.label_size_regex return nil if match.blank? atts = {} if !match[1].blank? atts[:width] = match[1] end if !match[2].blank? atts[:height] = match[2] end if !match[3].blank? atts[:aspect_mode] = match[3] end atts[:label] = label_string #atts[:label] = "#{atts[:width]}x#{atts[:height]}" #atts[:label] += "_#{atts[:aspect_mode]}" if atts[:aspect_mode] atts end |
#create_label_from_size_string(size_string) ⇒ Object
243 244 245 246 247 248 249 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 243 def create_label_from_size_string(size_string) if size_string.match ActsAsCloudhdr.size_string_regex size_string = size_string.gsub("!","crop") size_string = size_string.gsub(">","preserve") end size_string end |
#image?(content_type) ⇒ Boolean
138 139 140 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 138 def image?(content_type) image_types.include?(content_type) end |
#image_types ⇒ Object
The list of content types that will trigger image handling.
125 126 127 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 125 def image_types web_safe_image_types + other_image_types end |
#thumbnail_attributes_for(thumbnail_name = "small") ⇒ Object
232 233 234 235 236 237 238 239 240 241 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 232 def thumbnail_attributes_for(thumbnail_name = "small") atts = self.cloudhdr_thumbnails.select{|atts| atts[:label] == thumbnail_name }.first if atts.blank? atts = create_atts_from_size_string(thumbnail_name) end if atts.blank? raise ThumbnailAttributesNotFoundError.new("No thumbnail attributes were found for label '#{thumbnail_name}'") end atts end |
#update_from_cloudhdr(params) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 200 def update_from_cloudhdr(params) Rails.logger.debug "tying to call update from cloudhdr for params = #{params.to_json}" if !params[:output].blank? Rails.logger.debug "find_by_cloudhdr_output_id #{params[:output][:id]}" iu = find_by_cloudhdr_output_id params[:output][:id] Rails.logger.debug "the item = #{iu}" img_params = params[:output] iu.filename = File.basename(params[:output][:url]) #if iu.filename.blank? if ActsAsCloudhdr.storeage_mode == "local" iu.save_url(params[:output][:url]) end else iu = find_by_cloudhdr_input_id params[:input][:id] img_params = params[:input] end [:file_size,:width,:height,:taken_at,:lat,:lng].each do |att| setter = att.to_s + "=" if iu.respond_to? setter and !img_params[att].blank? iu.send setter, img_params[att] end end #iu.file_size = img_params[:file_size] #iu.width = img_params[:width] #iu.height = img_params[:height] iu.cloudhdr_status = "ready" iu.save iu end |
#validates_cloudhdr ⇒ Object
end
196 197 198 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 196 def validates_cloudhdr validates_presence_of :content_type, :filename, :if=>lambda{ parent_id.blank? } end |
#web_safe?(content_type) ⇒ Boolean
142 143 144 |
# File 'lib/cloudhdr_rails/acts_as_cloudhdr.rb', line 142 def web_safe?(content_type) web_safe_image_types.include?(content_type) end |