Sha256: 99b1a9f4c6c0cc7d3162c85e0bd60bec9ec95553562d04c5f56c80e4fdda2014

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

module Stastic::Command
  class Set < Base
    attr_accessor :settings

    VALID_SETTINGS = [:site_root, :site_id]

    def initialize(args = [])
      case args.size
      when 0
        raise(Stastic::Command::InvalidOptions)
      else
        self.settings = parse_args(args)
        validate_settings(settings)
      end
    end

    def index
      update_settings(settings)
    end

    private
      def parse_args(args)
        args.inject(Hash.new) do |h,arg|
          k,v = arg.split('=')
          h[k.to_sym] = v
          h
        end
      end

      def validate_settings(settings)
        raise(Stastic::Command::InvalidOptions) unless settings.keys.all? {|key| VALID_SETTINGS.include?(key)}
      end

      def set_name(name)
        print "Changing Site Name... "
        begin
          response = Stastic::Client.request(:put, "/sites/#{Stastic::Config.site_id}", {:site => {:name => name}})
        rescue Stastic::InvalidCredentials
          request_credentials
          retry 
        rescue Stastic::ValidationFailed
          print "Could not change site name\n"
          exit
        end

        puts "Success\n"
        true
      end

      def update_settings(settings)
        Stastic::Config.update(settings)
      end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stastic-0.2.7 lib/stastic/commands/set.rb
stastic-0.2.6 lib/stastic/commands/set.rb
stastic-0.2.5 lib/stastic/commands/set.rb
stastic-0.2.4 lib/stastic/commands/set.rb
stastic-0.2.3 lib/stastic/commands/set.rb
stastic-0.2.2 lib/stastic/commands/set.rb
stastic-0.2.1 lib/stastic/commands/set.rb
stastic-0.2.0 lib/stastic/commands/set.rb