• RisingCode

  • Bookmarks

  • About


  • Controllers

    • class RisingCode::Controllers::Contact < R('/contact')
        def get
          @tags = Tag.find_all_by_include_in_header(true)
          render(:contact)
        end
        
        def post
          # do nothing
        end
      end
    • class RisingCode::Controllers::CreateOrUpdateImage < R('/dashboard/image/(\d*)')
        def get(image_id)
          administer do
            if image_id.blank? then
              @image = Image.new
            else
              @image = Image.find_by_id(image_id)
            end
            render(:create_or_update_image)
          end
        end
        
        def post(image_id)
          administer do
            if image_id.blank? then
              @image = Image.new
            else
              @image = Image.find_by_id(image_id)
            end
            unless @input.the_file.is_a?(String) then
              @image.x_put(@input.the_file[:tempfile].read)
            end
            @image.save!
            redirect(R(CreateOrUpdateImage, @image.id))
          end
        end
      end
    • class RisingCode::Controllers::RetrieveTags < R('/dashboard/tags')
        def get
          administer do
            @tags = Tag.find(:all)
            render(:list_tags)
          end
        end
        
        def post
          @input.tag_ids.each do |tag_id|
            tag = Tag.find(tag_id)
            tag.destroy
          end
          redirect(R(RetrieveTags))
        end
      end
    • class RisingCode::Controllers::Comments < R('/comment/(\d+)(.*)')
        def post(article_id, junk = nil)
          return @input.inspect
        end
      end
    • class RisingCode::Controllers::BookmarksByTag < R('/bookmarks/tagged/(.*)')
        def get(tag)
          @tag = tag
          @tags = Tag.find_all_by_include_in_header(true)
          @bookmarks = Delicious::Bookmarks.all(0, 99999)
          @bookmarks_for_tag = []
          @bookmarks.each do |date, bookmarks|
            bookmarks.each do |bookmark|
              (@bookmarks_for_tag << bookmark) if bookmark["tag"].include?(tag)
            end
          end
          render(:bookmarks_by_tag)
        end
      end
    • class RisingCode::Controllers::About < R('/about')
        def get
          @tags = Tag.find_all_by_include_in_header(true)
          render(:about)
        end
      end
    • class RisingCode::Controllers::Images < R('/images/','/images/public/([a-zA-Z0-9\-]+).png','/images/([a-zA-Z0-9\-]+)/(\d*)')
        def get(*args)
          if (args.length == 0) then
            view_images do
              @tags = Tag.find_all_by_include_in_header(true)
              @images = Image.find(:all, :order => "created_at desc")
              render(:images)
            end
          else
            args.inspect
          end
        end
      end
    • class RisingCode::Controllers::Dashboard < R('/dashboard')
        def get
          administer { render(:dashboard) }
        end
      end
    • unknown
    • class RisingCode::Controllers::CreateOrUpdateArticle < R('/dashboard/article/(\d*)')
        def get(article_id)
          administer do
            if article_id.blank? then
              @article = Article.new
              @article.autopop
            else
              @article = Article.find_by_id(article_id)
            end
            render(:create_or_update_article)
          end
        end
        
        def post(article_id)
          administer do
            if article_id.blank? then
              @article = Article.new
            else
              @article = Article.find_by_id(article_id)
            end
            @article.title = @input.title
            @article.permalink = @input.permalink
            @article.excerpt = @input.excerpt
            @article.body = @input.body
            @article.published_on = @input.published_on
            @article.tag_list = @input.tag_list
            redirect(CreateOrUpdateArticle, @article.id) if @article.save!
          end
        end
      end
    • class RisingCode::Controllers::Index < R('/','/(articles)','/([a-zA-Z0-9 ]+)/(\d*)','/(\d+)/(\d+)/(\d+)','/(\w+)/(\w+)/(\w+)/([\w-]+)')
        def get(*args)
          @limit = 5
          @offset = 0
          @use_page_navigation = false
          @use_date_navigation = false
          @include_openid_delegation = false
          @tags = Tag.find_all_by_include_in_header(true)
          if args.empty? then
            @limit = 1
            @current_action = :index
            @permalink = "%"
            @now = Time.now
            @use_date_navigation = true
            @include_openid_delegation = true
          else
            if (args.length == 1) then
              @articles = Article.find(:all, :order => "published_on asc")
              @use_date_navigation = true
              return render(:articles)
            else
              if (args.length == 2) then
                @permalink = "%"
                @now = Time.now
                @tag = args[0]
                @page = args[1].to_i
                @offset = ((@page - 1) * @limit) if (@page > 0)
                @articles = Article.find_tagged_with(@tag, :limit => @limit, :offset => @offset, :conditions => ["permalink like ? and (date(published_on) <= ?)", @permalink, @now], :order => "published_on desc")
                @current_action = @tag.to_s.intern
                @use_page_navigation = true
              else
                if (args.length == 3) then
                  @permalink = "%"
                  @now = Date.parse(args.join("/"))
                  @limit = 99
                  @use_date_navigation = true
                else
                  @permalink = ("/" + args.join("/"))
                  @now = Time.now
                  @limit = 1
                  @use_date_navigation = true
                end
              end
            end
          end
          if @articles.nil? then
            @articles = Article.find(:all, :limit => @limit, :offset => @offset, :conditions => ["permalink like ? and (date(published_on) <= ? or ?)", @permalink, @now, user_logged_in], :order => "published_on desc")
          end
          if (@articles.length > 0) then
            @old_ranger = Article.find(:first, :conditions => ["date(published_on) <= ? and id < ?", Time.now, @articles.last.id], :limit => @limit, :order => "published_on asc")
          end
          if (@articles.length > 0) then
            @new_ranger = Article.find(:first, :conditions => ["date(published_on) <= ? and id > ?", Time.now, @articles.first.id], :limit => @limit, :order => "published_on desc")
          end
          @single = (@articles.length == 1)
          render(:index)
        end
      end
    • class RisingCode::Controllers::RetrieveImages < R('/dashboard/images')
        def get
          administer do
            @images = Image.find(:all)
            render(:list_images)
          end
        end
        
        def post
          @input.image_ids.each do |image_id|
            image = Image.find(image_id)
            image.destroy
          end
          redirect(R(RetrieveImages))
        end
      end
    • class RisingCode::Controllers::Button < R('/button/(.*)')
        def get(id)
          id ||= "GO"
          label = Draw.new
          label.fill = "black"
          label.stroke = "none"
          label.font = "Vera"
          label.text_antialias(true)
          label.font_style = Magick::NormalStyle
          label.font_weight = Magick::BoldWeight
          label.gravity = Magick::CenterGravity
          label.text(0, 0, id)
          metrics = label.get_type_metrics(id)
          width = metrics.width
          height = metrics.height
          width = (width + 16)
          height = (height + 12)
          radius = 4
          top_grad = GradientFill.new(0, 0, width, 0, "#ffffff", "#cccccc")
          image_layer_one = Magick::Image.new(width, height, top_grad)
          gc = Draw.new
          gc.roundrectangle(0, 0, (image_layer_one.columns - 1), (image_layer_one.rows - 1), radius, radius)
          gc.composite(0, 0, 0, 0, image_layer_one, InCompositeOp)
          new_layer_one = Magick::Image.new(width, height) { self.background_color = "none" }
          gc.draw(new_layer_one)
          inner_glow_mask = Magick::Image.new(width, height) { self.background_color = "none" }
          gc = Draw.new
          gc.stroke("black")
          gc.stroke_width(1)
          gc.fill("white")
          gc.roundrectangle(1, 1, (inner_glow_mask.columns - 2), (inner_glow_mask.rows - 2), radius, radius)
          gc.draw(inner_glow_mask)
          inner_glow_mask = inner_glow_mask.blur_image(0, 1)
          highlight_gradient = GradientFill.new(0, 0, 80, 0, "#ffffff", "#e4e4e4")
          highlight_layer = Magick::Image.new((width - 14).to_i, (height * 0.5).to_i, highlight_gradient)
          gc = Draw.new
          gc.roundrectangle(0, 0, (highlight_layer.columns - 1), (highlight_layer.rows - 1), radius, radius)
          gc.composite(0, 0, 0, 0, highlight_layer, InCompositeOp)
          new_highlight_layer = Magick::Image.new(highlight_layer.columns, highlight_layer.rows) do
            self.background_color = "none"
          end
          gc.draw(new_highlight_layer)
          new_layer_one.composite!(inner_glow_mask, CenterGravity, MultiplyCompositeOp)
          new_layer_one.composite!(new_highlight_layer, NorthGravity, 4, 3, OverCompositeOp)
          label.draw(new_layer_one)
          final_image = new_layer_one
          blob = final_image.to_blob do
            self.format = "GIF"
            self.quality = 100
          end
          @headers["Content-Type"] = "image/gif"
          @headers["Content-Disposition"] = "inline"
          return blob
        end
      end
    • class RisingCode::Controllers::Sources < R('/sources')
        def get
          @tags = Tag.find_all_by_include_in_header(true)
          @controllers = Hash.new
          @models = Hash.new
          DocumentationServer::SERVER.controllers.each do |controller|
            @controllers[controller] = DocumentationServer::SERVER.source_for(controller)
          end
          DocumentationServer::SERVER.models.each do |model|
            @models[model] = DocumentationServer::SERVER.source_for(model)
          end
          render(:sources)
        end
      end
    • class RisingCode::Controllers::Resume < R('/about/resume')
        def get
          other_layout { render(:resume) }
        end
      end
    • class RisingCode::Controllers::Login < R('/dashboard/login(.*)')
        def get(*args)
          if @input.has_key?("openid.mode") then
            this_url = (@@realm + R(Login, nil))
            store = ::OpenID::Store::Filesystem.new("/tmp")
            openid_consumer = ::OpenID::Consumer.new(@state, store)
            openid_response = openid_consumer.complete(@input, this_url)
            if ((openid_response.status == :success) and (openid_response.identity_url == "http://diclophis.pip.verisignlabs.com/")) then
              @state.authenticated = true
              return redirect(R(Dashboard))
            end
          end
          other_layout { render(:login) }
        end
        
        def post(*args)
          if (@input.identity_url == @@identity_url) then
            store = ::OpenID::Store::Filesystem.new("/tmp")
            openid_consumer = ::OpenID::Consumer.new(@state, store)
            check_id_request = openid_consumer.begin(@input.identity_url)
            openid_sreg = ::OpenID::SReg::Request.new(["nickname"])
            check_id_request.add_extension(openid_sreg)
            url = check_id_request.redirect_url(@@realm, (@@realm + R(Login, nil)))
            redirect(url)
          end
        end
      end
    • class RisingCode::Controllers::Bookmarks < R('/bookmarks','/bookmarks/(\d+)/(\d+)/(\d+)')
        def get(*args)
          @tags = Tag.find_all_by_include_in_header(true)
          @bookmarks = Delicious::Bookmarks.all(0, 99999)
          @bookmarks_for_today = nil
          @bookmarks_for_tomorrow = nil
          @bookmarks_for_yesterday = nil
          @days = @bookmarks.keys.sort
          @index = nil
          case args.length
          when 0 then
            @today = Time.now
            until @index = @days.index(@today.strftime("%Y-%m-%d")) do
              @today = (@today - 24.hours)
            end
            return redirect(R(Bookmarks, @today.year, @today.month, @today.day))
          when 3 then
            @today = Date.parse(args.join("/"))
            @index = @days.index(@today.strftime("%Y-%m-%d"))
          else
            # do nothing
          end
          if @index then
            @bookmarks_for_today = @bookmarks[@today.strftime("%Y-%m-%d")]
            if @days[(@index + 1)] then
              @tomorrow = Date.parse(@days[(@index + 1)])
              @bookmarks_for_tomorrow = @bookmarks[@tomorrow.strftime("%Y-%m-%d")]
            end
            if @days[(@index - 1)] then
              @yesterday = Date.parse(@days[(@index - 1)])
              @bookmarks_for_yesterday = @bookmarks[@yesterday.strftime("%Y-%m-%d")]
            end
            render(:bookmarks)
          else
            redirect(R(Bookmarks))
          end
        end
      end
    • class RisingCode::Controllers::Learn < R('/learn/about/(.*)')
        def get(tag)
          @tag = tag
          @tags = Tag.find_all_by_include_in_header(true)
          render(:message)
        end
      end
    • class RisingCode::Controllers::Logout < R('/dashboard/logout')
        def get
          log_user_out
          redirect(R(Index))
        end
      end
    • class RisingCode::Controllers::CreateOrUpdateTag < R('/dashboard/tag/(\d*)')
        def get(tag_id)
          administer do
            tag_id.blank? ? (@tag = Tag.new) : (@tag = Tag.find_by_id(tag_id))
            render(:create_or_update_tag)
          end
        end
        
        def post(tag_id)
          administer do
            tag_id.blank? ? (@tag = Tag.new) : (@tag = Tag.find_by_id(tag_id))
            @tag.name = @input.name
            @tag.include_in_header = @input.include_in_header.nil? ? (false) : (true)
            if @tag.save! then
              redirect(R(CreateOrUpdateTag, @tag.id))
            else
              render(:create_or_update_tag)
            end
          end
        end
      end
    • class RisingCode::Controllers::RetrieveArticles < R('/dashboard/articles')
        def get
          administer do
            @articles = Article.find(:all)
            render(:list_articles)
          end
        end
        
        def post
          @input.article_ids.each do |article_id|
            article = Article.find(article_id)
            article.destroy
          end
          redirect(R(RetrieveArticles))
        end
      end
  • Models

    • class RisingCode::Models::Article < ActiveRecord::Base
        def after_create_or_update_associated_records_for_comments
          if instance_variable_defined?("#{ivar}") then
            association = instance_variable_get("#{ivar}")
          end
          records_to_save = if @new_record_before_save then
            association
          else
            if (association.respond_to?(:loaded?) and association.loaded?) then
              association.select { |record| record.new_record? }
            else
              if (association.respond_to?(:loaded?) and (not association.loaded?)) then
                association.target.select { |record| record.new_record? }
              else
                []
              end
            end
          end
          unless records_to_save.blank? then
            records_to_save.each { |record| association.send(:insert_record, record) }
          end
          association.send(:construct_sql) if association.respond_to?(:construct_sql)
        end
        
        def after_create_or_update_associated_records_for_taggings
          if instance_variable_defined?("#{ivar}") then
            association = instance_variable_get("#{ivar}")
          end
          records_to_save = if @new_record_before_save then
            association
          else
            if (association.respond_to?(:loaded?) and association.loaded?) then
              association.select { |record| record.new_record? }
            else
              if (association.respond_to?(:loaded?) and (not association.loaded?)) then
                association.target.select { |record| record.new_record? }
              else
                []
              end
            end
          end
          unless records_to_save.blank? then
            records_to_save.each { |record| association.send(:insert_record, record) }
          end
          association.send(:construct_sql) if association.respond_to?(:construct_sql)
        end
        
        def after_create_or_update_associated_records_for_tags
          if instance_variable_defined?("#{ivar}") then
            association = instance_variable_get("#{ivar}")
          end
          records_to_save = if @new_record_before_save then
            association
          else
            if (association.respond_to?(:loaded?) and association.loaded?) then
              association.select { |record| record.new_record? }
            else
              if (association.respond_to?(:loaded?) and (not association.loaded?)) then
                association.target.select { |record| record.new_record? }
              else
                []
              end
            end
          end
          unless records_to_save.blank? then
            records_to_save.each { |record| association.send(:insert_record, record) }
          end
          association.send(:construct_sql) if association.respond_to?(:construct_sql)
        end
        
        def autopop(title = nil)
          self.title = title
          self.published_on = Time.now
          (1..100).each do |i|
            self.permalink = "/#{published_on.year}/#{published_on.month}/#{published_on.day}/#{i.ordinalize}"
            break if valid?
          end
        end
        
        def before_save_associated_records_for_comments
          @new_record_before_save = new_record?
          true
        end
        
        def before_save_associated_records_for_taggings
          @new_record_before_save = new_record?
          true
        end
        
        def before_save_associated_records_for_tags
          @new_record_before_save = new_record?
          true
        end
        
        def belongs_to_before_save_for_user
          if instance_variable_defined?("#{ivar}") then
            association = instance_variable_get("#{ivar}")
          end
          unless association.nil? then
            association.save(true) if association.new_record?
            if association.updated? then
              self["#{reflection.primary_key_name}"] = association.id
            end
          end
        end
        
        def build_user(*params)
          ivar = "@#{reflection.name}"
          attributees = params.first unless params.empty?
          replace_existing = params[1].nil? ? (true) : (params[1])
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if association.nil? then
            association = association_proxy_class.new(self, reflection)
            instance_variable_set(ivar, association)
          end
          if (association_proxy_class == HasOneAssociation) then
            association.send(constructor, attributees, replace_existing)
          else
            association.send(constructor, attributees)
          end
        end
        
        def comment_ids
          send(reflection.name).map(&:id)
        end
        
        def comment_ids=(new_value)
          ids = (new_value or []).reject { |nid| nid.blank? }
          send("#{reflection.name}=", reflection.class_name.constantize.find(ids))
        end
        
        def comments(*params)
          ivar = "@#{reflection.name}"
          force_reload = params.first unless params.empty?
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          unless association.respond_to?(:loaded?) then
            association = association_proxy_class.new(self, reflection)
            instance_variable_set(ivar, association)
          end
          association.reload if force_reload
          association
        end
        
        def comments=(new_value)
          association = send(reflection.name)
          association.replace(new_value)
          association
        end
        
        def create_user(*params)
          ivar = "@#{reflection.name}"
          attributees = params.first unless params.empty?
          replace_existing = params[1].nil? ? (true) : (params[1])
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if association.nil? then
            association = association_proxy_class.new(self, reflection)
            instance_variable_set(ivar, association)
          end
          if (association_proxy_class == HasOneAssociation) then
            association.send(constructor, attributees, replace_existing)
          else
            association.send(constructor, attributees)
          end
        end
        
        def has_many_dependent_destroy_for_taggings
          send("#{reflection.name}").each { |o| o.destroy }
        end
        
        def reload(*args)
          @tag_list = nil
          reload_without_tag_list(*args)
        end
        
        def reload_without_tag_list(*args)
          record = reload_without_dirty(*args)
          changed_attributes.clear
          record
        end
        
        def set_user_target(target)
          if (target.nil? and (association_proxy_class == BelongsToAssociation)) then
            return
          end
          association = association_proxy_class.new(self, reflection)
          association.target = target
          instance_variable_set(ivar, association)
        end
        
        def tag_ids
          send(reflection.name).map(&:id)
        end
        
        def tag_ids=(new_value)
          ids = (new_value or []).reject { |nid| nid.blank? }
          send("#{reflection.name}=", reflection.class_name.constantize.find(ids))
        end
        
        def tagging_ids
          send(reflection.name).map(&:id)
        end
        
        def tagging_ids=(new_value)
          ids = (new_value or []).reject { |nid| nid.blank? }
          send("#{reflection.name}=", reflection.class_name.constantize.find(ids))
        end
        
        def taggings(*params)
          ivar = "@#{reflection.name}"
          force_reload = params.first unless params.empty?
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          unless association.respond_to?(:loaded?) then
            association = association_proxy_class.new(self, reflection)
            instance_variable_set(ivar, association)
          end
          association.reload if force_reload
          association
        end
        
        def taggings=(new_value)
          association = send(reflection.name)
          association.replace(new_value)
          association
        end
        
        def tags(*params)
          ivar = "@#{reflection.name}"
          force_reload = params.first unless params.empty?
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          unless association.respond_to?(:loaded?) then
            association = association_proxy_class.new(self, reflection)
            instance_variable_set(ivar, association)
          end
          association.reload if force_reload
          association
        end
        
        def tags=(new_value)
          association = send(reflection.name)
          association.replace(new_value)
          association
        end
        
        def user(*params)
          force_reload = params.first unless params.empty?
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if (association.nil? or force_reload) then
            association = association_proxy_class.new(self, reflection)
            retval = association.reload
            if (retval.nil? and (association_proxy_class == BelongsToAssociation)) then
              instance_variable_set(ivar, nil)
              return nil
            end
            instance_variable_set(ivar, association)
          end
          association.target.nil? ? (nil) : (association)
        end
        
        def user=(new_value)
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if (association.nil? or (not (association.target == new_value))) then
            association = association_proxy_class.new(self, reflection)
          end
          if (association_proxy_class == HasOneThroughAssociation) then
            association.create_through_record(new_value)
            self.send(reflection.name, new_value)
          else
            association.replace(new_value)
            instance_variable_set(ivar, new_value.nil? ? (nil) : (association))
          end
        end
        
        def validate_associated_records_for_comments
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if association.respond_to?(:loaded?) then
            if new_record? then
              association
            else
              if association.loaded? then
                association.select { |record| record.new_record? }
              else
                association.target.select { |record| record.new_record? }
              end
            end.each do |record|
              errors.add("#{association_name}") unless record.valid?
            end
          end
        end
        
        def validate_associated_records_for_taggings
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if association.respond_to?(:loaded?) then
            if new_record? then
              association
            else
              if association.loaded? then
                association.select { |record| record.new_record? }
              else
                association.target.select { |record| record.new_record? }
              end
            end.each do |record|
              errors.add("#{association_name}") unless record.valid?
            end
          end
        end
        
        def validate_associated_records_for_tags
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if association.respond_to?(:loaded?) then
            if new_record? then
              association
            else
              if association.loaded? then
                association.select { |record| record.new_record? }
              else
                association.target.select { |record| record.new_record? }
              end
            end.each do |record|
              errors.add("#{association_name}") unless record.valid?
            end
          end
        end
        
        def tag_list
          return @tag_list if @tag_list
          if (self.class.caching_tag_list? and (not (cached_value = send(self.class.cached_tag_list_column_name)).nil?)) then
            @tag_list = TagList.from(cached_value)
          else
            @tag_list = TagList.new(*tags.map(&:name))
          end
        end
        
        def tag_counts(options = {  })
          self.class.tag_counts({ :conditions => self.class.send(:tags_condition, tag_list) }.reverse_merge!(options))
        end
        
        def tag_list=(value)
          @tag_list = TagList.from(value)
        end
        
        def save_tags
          return unless @tag_list
          new_tag_names = (@tag_list - tags.map(&:name))
          old_tags = tags.reject { |tag| @tag_list.include?(tag.name) }
          self.class.transaction do
            tags.delete(*old_tags) if old_tags.any?
            new_tag_names.each do |new_tag_name|
              (tags << RisingCode::Models::Tag.find_or_create_with_like_by_name(new_tag_name))
            end
          end
          true
        end
        
        def reload_with_tag_list(*args)
          @tag_list = nil
          reload_without_tag_list(*args)
        end
        
        def save_cached_tag_list
          if self.class.caching_tag_list? then
            self[self.class.cached_tag_list_column_name] = tag_list.to_s
          end
        end
      end
    • unknown
    • class RisingCode::Models::Image < ActiveRecord::Base
        def full_permalink
          public_link(:main)
        end
        
        def get_key(x_key)
          RightAws::S3::Key.create(@@bucket, ((self.permalink + "_") + x_key.to_s))
        end
        
        def icon_permalink
          public_link(:icon)
        end
        
        def public_link(x_key = :main)
          get_key(x_key).public_link
        end
        
        def put_key(x_key, blob)
          get_key(x_key).put(blob, "public-read")
        end
        
        def thumb_permalink
          public_link(:thumb)
        end
        
        def x_put(blob)
          self.permalink = UUID.random_create.to_s if self.permalink.blank?
          imgs = Magick::Image.from_blob(blob)
          first = imgs.first
          case (first.get_exif_by_entry("Orientation") and first["EXIF:Orientation"])
          when "6" then
            first.rotate!(90)
            first["EXIF:Orientation"] = "1"
          when "3" then
            first.rotate!(180)
            first["EXIF:Orientation"] = "1"
          when "8" then
            first.rotate!(270)
            first["EXIF:Orientation"] = "1"
          else
            # do nothing
          end
          sizes = { :main => { :cols => 640, :rows => 480 }, :thumb => { :cols => 400 }, :icon => { :cols => 128 } }.each do |x_key, size|
            geometry = size[:rows] ? ("#{size[:cols]}x#{size[:rows]}>") : ("#{size[:cols]}x")
            first.change_geometry(geometry) do |cols, rows, img|
              put_key(x_key, img.resize(cols, rows).to_blob)
            end
          end
        end
      end
    • unknown
    • class RisingCode::Models::Tag < ActiveRecord::Base
        def ==(object)
          (super or (object.is_a?(Tag) and (name == object.name)))
        end
        
        def after_create_or_update_associated_records_for_taggings
          if instance_variable_defined?("#{ivar}") then
            association = instance_variable_get("#{ivar}")
          end
          records_to_save = if @new_record_before_save then
            association
          else
            if (association.respond_to?(:loaded?) and association.loaded?) then
              association.select { |record| record.new_record? }
            else
              if (association.respond_to?(:loaded?) and (not association.loaded?)) then
                association.target.select { |record| record.new_record? }
              else
                []
              end
            end
          end
          unless records_to_save.blank? then
            records_to_save.each { |record| association.send(:insert_record, record) }
          end
          association.send(:construct_sql) if association.respond_to?(:construct_sql)
        end
        
        def before_save_associated_records_for_taggings
          @new_record_before_save = new_record?
          true
        end
        
        def count
          read_attribute(:count).to_i
        end
        
        def destroy_unused
          @@destroy_unused
        end
        
        def destroy_unused=(obj)
          @@destroy_unused = obj
        end
        
        def tagging_ids
          send(reflection.name).map(&:id)
        end
        
        def tagging_ids=(new_value)
          ids = (new_value or []).reject { |nid| nid.blank? }
          send("#{reflection.name}=", reflection.class_name.constantize.find(ids))
        end
        
        def taggings(*params)
          ivar = "@#{reflection.name}"
          force_reload = params.first unless params.empty?
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          unless association.respond_to?(:loaded?) then
            association = association_proxy_class.new(self, reflection)
            instance_variable_set(ivar, association)
          end
          association.reload if force_reload
          association
        end
        
        def taggings=(new_value)
          association = send(reflection.name)
          association.replace(new_value)
          association
        end
        
        def to_s
          name
        end
        
        def validate_associated_records_for_taggings
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if association.respond_to?(:loaded?) then
            if new_record? then
              association
            else
              if association.loaded? then
                association.select { |record| record.new_record? }
              else
                association.target.select { |record| record.new_record? }
              end
            end.each do |record|
              errors.add("#{association_name}") unless record.valid?
            end
          end
        end
        
        def self.destroy_unused
          @@destroy_unused
        end
        
        def self.destroy_unused=(obj)
          @@destroy_unused = obj
        end
        
        def self.find_or_create_with_like_by_name(name)
          (find(:first, :conditions => ["name LIKE ?", name]) or create(:name => name))
        end
      end
    • class RisingCode::Models::Tagging < ActiveRecord::Base
        def after_destroy
          tag.destroy if (Tag.destroy_unused and tag.taggings.count.zero?)
        end
        
        def belongs_to_before_save_for_tag
          if instance_variable_defined?("#{ivar}") then
            association = instance_variable_get("#{ivar}")
          end
          unless association.nil? then
            association.save(true) if association.new_record?
            if association.updated? then
              self["#{reflection.primary_key_name}"] = association.id
            end
          end
        end
        
        def build_tag(*params)
          ivar = "@#{reflection.name}"
          attributees = params.first unless params.empty?
          replace_existing = params[1].nil? ? (true) : (params[1])
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if association.nil? then
            association = association_proxy_class.new(self, reflection)
            instance_variable_set(ivar, association)
          end
          if (association_proxy_class == HasOneAssociation) then
            association.send(constructor, attributees, replace_existing)
          else
            association.send(constructor, attributees)
          end
        end
        
        def create_tag(*params)
          ivar = "@#{reflection.name}"
          attributees = params.first unless params.empty?
          replace_existing = params[1].nil? ? (true) : (params[1])
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if association.nil? then
            association = association_proxy_class.new(self, reflection)
            instance_variable_set(ivar, association)
          end
          if (association_proxy_class == HasOneAssociation) then
            association.send(constructor, attributees, replace_existing)
          else
            association.send(constructor, attributees)
          end
        end
        
        def polymorphic_belongs_to_before_save_for_taggable
          if instance_variable_defined?("#{ivar}") then
            association = instance_variable_get("#{ivar}")
          end
          if (association and association.target) then
            association.save(true) if association.new_record?
            if association.updated? then
              self["#{reflection.primary_key_name}"] = association.id
              self["#{reflection.options[:foreign_type]}"] = association.class.base_class.name.to_s
            end
          end
        end
        
        def set_tag_target(target)
          if (target.nil? and (association_proxy_class == BelongsToAssociation)) then
            return
          end
          association = association_proxy_class.new(self, reflection)
          association.target = target
          instance_variable_set(ivar, association)
        end
        
        def set_taggable_target(target)
          if (target.nil? and (association_proxy_class == BelongsToAssociation)) then
            return
          end
          association = association_proxy_class.new(self, reflection)
          association.target = target
          instance_variable_set(ivar, association)
        end
        
        def tag(*params)
          force_reload = params.first unless params.empty?
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if (association.nil? or force_reload) then
            association = association_proxy_class.new(self, reflection)
            retval = association.reload
            if (retval.nil? and (association_proxy_class == BelongsToAssociation)) then
              instance_variable_set(ivar, nil)
              return nil
            end
            instance_variable_set(ivar, association)
          end
          association.target.nil? ? (nil) : (association)
        end
        
        def tag=(new_value)
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if (association.nil? or (not (association.target == new_value))) then
            association = association_proxy_class.new(self, reflection)
          end
          if (association_proxy_class == HasOneThroughAssociation) then
            association.create_through_record(new_value)
            self.send(reflection.name, new_value)
          else
            association.replace(new_value)
            instance_variable_set(ivar, new_value.nil? ? (nil) : (association))
          end
        end
        
        def taggable(*params)
          force_reload = params.first unless params.empty?
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if (association.nil? or force_reload) then
            association = association_proxy_class.new(self, reflection)
            retval = association.reload
            if (retval.nil? and (association_proxy_class == BelongsToAssociation)) then
              instance_variable_set(ivar, nil)
              return nil
            end
            instance_variable_set(ivar, association)
          end
          association.target.nil? ? (nil) : (association)
        end
        
        def taggable=(new_value)
          if instance_variable_defined?(ivar) then
            association = instance_variable_get(ivar)
          end
          if (association.nil? or (not (association.target == new_value))) then
            association = association_proxy_class.new(self, reflection)
          end
          if (association_proxy_class == HasOneThroughAssociation) then
            association.create_through_record(new_value)
            self.send(reflection.name, new_value)
          else
            association.replace(new_value)
            instance_variable_set(ivar, new_value.nil? ? (nil) : (association))
          end
        end
      end