Sha256: 65ca97f6241a65e40999cb80cfcf484ac2bce50f9bb37208c8b63324ee9e6522

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'thor'

module InlineEncryption

  class CLI < Thor

    class_option :config, :aliases => ["-c"], :type => :string

    def initialize(args=[], opts=[], config={})
      super(args, opts, config)

      if options[:config] && File.exists?(options[:config])
        @options = YAML.load_file(options[:config]).symbolize_keys.merge(@options.symbolize_keys)
      end
    end


    desc "encrypt [DATA]", "encrypt stuff"
    class_option :require, :aliases => ["-r"], :type => :string
    def encrypt(data)
      #puts options
      load_enviroment(options[:require])

      puts InlineEncryption.encrypt(data)
    end



    protected


    def load_enviroment(file=nil)
      file ||= "."

      if File.directory?(file) && File.exists?(File.expand_path("#{file}/config/environment.rb"))
        require "rails"
        require File.expand_path("#{file}/config/environment.rb")
        if defined?(::Rails) && ::Rails.respond_to?(:application)
          # Rails 3
          # ::Rails.application.eager_load!
        end
      elsif File.file?(file)
        require File.expand_path(file)
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inline_encryption-0.0.6 lib/inline_encryption/cli.rb