Sha256: b5bbbdfd5e1501a754a0ca49249b647044d5f4a422abf8e0fbcc538aa39c267e

Contents?: true

Size: 1.67 KB

Versions: 16

Compression:

Stored size: 1.67 KB

Contents

# -*- coding: utf-8 -*-
#
# @file 
# @brief
# @author ongaeshi
# @date   2012/02/21

require 'milkode/common/util'

module Milkode
  class Package
    def self.create(dir, ignore=nil)
      if ignore && ignore.size > 0
        Package.new({"directory" => dir, "ignore" => ignore})
      else
        Package.new({"directory" => dir})
      end
    end

    def initialize(hash)
      @hash = hash
      normalize
    end

    def name
      if options[:name]
        options[:name]
      else
        File.basename(directory)
      end
    end

    def directory
      @hash['directory']
    end

    def ignore
      @hash['ignore'] || []
    end

    def set_ignore(ignore)
      @hash['ignore'] = ignore
    end

    def options
      @hash['options'] || {}
    end

    def set_options(options)
      @hash['options'] = options
    end

    def hash
      @hash
    end

    def migrate
      # 色々あって、ignore値はデフォルトで設定しないようにした
      # @hash['ignore'] = [] unless ignore
    end

    # 同名パッケージか?
    def same_name?(a_name)
      name == a_name
    end

    # 同値検査
    def ==(rhs)
      name == rhs.name && directory == rhs.directory && ignore == rhs.ignore
    end

    def fav?
      options[:fav] == true
    end

    def set_fav(value)
      if value
        if @hash['options']
          @hash['options'][:fav] = true
        else
          @hash['options'] = {:fav => true}
        end
      else
        @hash['options'].delete(:fav) if @hash['options']
      end
    end

    private

    def normalize
      if (Util.platform_win?)
        @hash['directory'] = Util.normalize_filename(directory)
      end
    end
    
  end
end


Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
milkode-1.8.9.2 lib/milkode/cdstk/package.rb
milkode-1.8.9.1 lib/milkode/cdstk/package.rb
milkode-1.8.9 lib/milkode/cdstk/package.rb
milkode-1.8.8 lib/milkode/cdstk/package.rb
milkode-1.8.7 lib/milkode/cdstk/package.rb
milkode-1.8.6 lib/milkode/cdstk/package.rb
milkode-1.8.5 lib/milkode/cdstk/package.rb
milkode-1.8.4 lib/milkode/cdstk/package.rb
milkode-1.8.3 lib/milkode/cdstk/package.rb
milkode-1.8.2 lib/milkode/cdstk/package.rb
milkode-1.8.1 lib/milkode/cdstk/package.rb
milkode-1.8.0 lib/milkode/cdstk/package.rb
milkode-1.7.1 lib/milkode/cdstk/package.rb
milkode-1.7.0 lib/milkode/cdstk/package.rb
milkode-1.6.1 lib/milkode/cdstk/package.rb
milkode-1.6.0 lib/milkode/cdstk/package.rb