Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mo betta the cast

  • Loading branch information...
commit 9f82ef0eca57c0991104b89b8d856e877f5f06f0 1 parent 3f3b56c
@ahoward authored
Showing with 28 additions and 14 deletions.
  1. +4 −0 TODO
  2. +1 −1  lib/main.rb
  3. +23 −13 lib/main/cast.rb
View
4 TODO
@@ -1,4 +1,8 @@
todo:
+ - support run once/singleton pattern via flock/lockfile
+ - config generation support
+
+
- support for logging/logs too!
- examples of new features
- use map.rb
View
2  lib/main.rb
@@ -2,7 +2,7 @@ module Main
#
# top level constants
#
- Main::VERSION = '4.5.1' unless
+ Main::VERSION = '4.6.0' unless
defined? Main::VERSION
def self.version() Main::VERSION end
View
36 lib/main/cast.rb
@@ -103,29 +103,39 @@ def self.cast m, &b
end
cast :list do |*objs|
- [*objs].flatten.join(',').split(/,/)
+ [*objs].flatten.join(',').split(/[\n,]/).map{|item| item.strip}.delete_if{|item| item.strip.empty?}
end
- # add list_of_xxx methods
+# add list_of_xxx methods
+#
List.dup.each do |type|
next if type.to_s =~ %r/list/
- m = "list_of_#{ type }"
- define_method m do |*objs|
- list(*objs).map{|obj| send type, obj}
+ %W" list_of_#{ type } list_of_#{ type }s ".each do |m|
+ define_method m do |*objs|
+ list(*objs).map{|obj| send type, obj}
+ end
+ export m
+ List << m
end
- export m
- List << m
end
- # add list_of_xxx_from_file
+# add list_of_xxx_from_file
+#
List.dup.each do |type|
next if type.to_s =~ %r/list/
- m = "list_of_#{ type }"
- define_method m do |*objs|
- list(*objs).map{|obj| send type, obj}
+ %W" list_of_#{ type }_from_file list_of_#{ type }s_from_file ".each do |m|
+ define_method m do |*args|
+ buf = nil
+ if args.size == 1 and args.first.respond_to?(:read)
+ buf = args.first.read
+ else
+ open(*args){|io| buf = io.read}
+ end
+ send(m.sub(/_from_file/, ''), buf)
+ end
+ export m
+ List << m
end
- export m
- List << m
end
def self.[] sym
Please sign in to comment.
Something went wrong with that request. Please try again.