Commits

Richo Healey  committed bde716b

Fix config structure

  • Participants
  • Parent commits 7e5b784

Comments (0)

Files changed (3)

         opts = ArgParse.new
         configure do |twat|
           opts.options.each do |key, value|
-            twat.send(:"#{key}=", value)
+            twat[key] = value
           end
         end
-        action = Actions.new
-        action.send(opts.options[:action], opts)
+        actor = Actions.new
+        actor.config = config
+        actor.send(opts.options[:action])
       rescue Usage
         opts.usage
       rescue NoSuchAccount
         puts "twat -a #{opts[:account]}"
       end
     end
-
-    # Stuff these off into a seperate piece of code somewhere
-    def configure(&block)
-      yield config
-
-      # If I understand correctly, I can check over what's
-      # happened here?
-    end
-
-    def config
-      @config ||= Config.new
-    end
-
   end
 end

File lib/twat/actions.rb

   CONSUMER_TOKENS = [ :consumer_key, :consumer_secret ]
   class Actions
 
-    def tweet(opts)
+    attr_accessor :config
+
+    def tweet
       # This is all broken, we should know what options we have before this happend
-      twitter_auth(opts)
+      twitter_auth(config)
 
-      Twitter.update(opts.msg)
+      Twitter.update(config.msg)
       #puts opts.msg
     end
 
-    def add(opts)
+    def add
       v = Config.consumer_info.map do |key, value|
         value
       end
       end
     end
 
-    def delete(opts)
+    def delete
       if cf.delete(opts[:account])
         cf.save!
         puts "Successfully deleted"
       end
     end
 
-    def show(opts)
+    def show
       twitter_auth(opts)
       Twitter.home_timeline.each_with_index do |tweet, idx|
         puts "#{tweet.user.screen_name}: #{tweet.text}"
       end
     end
 
-    def version(opts)
+    def version
       puts "twat: #{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
     end
 
     private
 
+    # This is bogus
     def cf
       @cf ||= Config.new
     end

File lib/twat/config.rb

 require 'ostruct'
 
 module Twat
-  class Config #< OpenStruct
+  class Twat
+    def configure(&block)
+      yield config
+
+      # If I understand correctly, I can check over what's
+      # happened here?
+    end
+
+    def config
+      @config ||= Config.new
+    end
+  end
+
+  class Config
 
     def config_path
       @config_path ||= ENV['TWAT_CONFIG'] || "#{ENV['HOME']}/.twatrc"
       end
     end
 
+    def method_missing(meth)
+      self[meth]
+    end
+
     def [](key)
       raise NoSuchAccount unless config.include?(key)
       config[key]