Skip to content

Commit

Permalink
Code cleanup, changed methods in Jared::Plugin to setters, fixed Jare…
Browse files Browse the repository at this point in the history
…d::PluginList parse.
  • Loading branch information
cyberarm committed Nov 24, 2014
1 parent dc1ee5b commit bef62f7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
14 changes: 5 additions & 9 deletions lib/jared/cli.rb
Expand Up @@ -5,16 +5,12 @@ def version
puts "Jared version #{Jared::VERSION}"
end

desc 'test', "test STUFF"
def test(stuffs)
puts "#{stuffs}"
end

# TODO: require gem before trying to defer to its thor subcommand class
Jared::PluginList.parse['plugins'].each do |plugin|
Jared::PluginList.new.parse['plugins'].each do |plugin|
desc plugin['command'], plugin['description']
define_method plugin['command'] do
subcommand plugin['command'], Module.const_get(plugin['main_class'].capitalize)
define_method plugin['command'] do |*args|
require plugin['rubygem_name'] if plugin['rubygem']
args, opts = Thor::Arguments.split(args)
invoke Module.const_get(plugin['main_class']), args, opts, :invoked_via_subcommand => true
end
end
end
Expand Down
32 changes: 20 additions & 12 deletions lib/jared/plugin.rb
@@ -1,51 +1,59 @@
module Jared
class Plugin
def plugin name
attr_reader :plugin, :description, :version, :command, :main_class,
:jared_version, :rubygem, :rubygem_name, :github, :github_repo,
:ruby_platform, :platform

def initialize
yield(self)
end

def plugin= name
@plugin = name
end

def description string
def description= string
@description = string ||= ""
end

def version string
def version= string
@version = string
end

def command string
def command= string
@command = string
end

def main_class string
def main_class= string
@main_class = string
end

def jared_version string
def jared_version= string
@jared_version = string
end

def rubygem boolean
def rubygem= boolean
@rubygem = boolean ||= false
end

def rubygem_name string
def rubygem_name= string
@rubygem_name = string ||= ""
end

def github boolean
def github= boolean
@github = boolean ||= false
end

def github_repo string
def github_repo= string
@github_repo = string ||= ""
end

def ruby_platform string
def ruby_platform= string
# ruby, cruby, jruby, or rbx
@ruby_platform = string ||= "ruby"
end

def platform string
def platform= string
# windows, linux, mac, unix, or a blank string for any platform.
@platform = ""
end
Expand Down
4 changes: 2 additions & 2 deletions lib/jared/plugin_list.rb
@@ -1,7 +1,7 @@
module Jared
class PluginList
def initialize
@file = "#{Dir.home}/.jared/data/plugins_list.json"
@file = "#{Dir.home}/.jared/data/jared-plugins.json"
end

def fetch
Expand All @@ -10,7 +10,7 @@ def fetch
end

def parse
MultiJson.load(@file)
MultiJson.load(File.open(@file).read)
end
end
end

0 comments on commit bef62f7

Please sign in to comment.