chimps 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,10 +9,8 @@ module Chimps
9
9
  false
10
10
  end
11
11
 
12
- attr_reader :data_file
13
-
14
12
  def data
15
- @data ||= merge_all *(data_from_stdin + data_from_file + data_from_command_line)
13
+ @data ||= merge_all(*(data_from_stdin + data_from_file + data_from_command_line)) || {}
16
14
  end
17
15
 
18
16
  protected
@@ -38,13 +36,13 @@ module Chimps
38
36
  d.merge!(obj)
39
37
  end
40
38
  end
41
- else raise CLIError.new("Unsuitable YAML data type #{data_type} -- can only combine Hashes and Arrays")
39
+ else raise CLIError.new("Incompatible YAML data type #{data_type} -- can only combine Hashes and Arrays")
42
40
  end
43
41
  end
44
42
 
45
43
  def params_from_command_line
46
44
  returning([]) do |d|
47
- argv.each_with_index do |arg, index|
45
+ config.argv.each_with_index do |arg, index|
48
46
  next if index == 0 && ignore_first_arg_on_command_line
49
47
  next unless arg =~ /^(\w+) *=(.*)$/
50
48
  name, value = $1.downcase.to_sym, $2.strip
@@ -55,7 +53,7 @@ module Chimps
55
53
 
56
54
  def yaml_files_from_command_line
57
55
  returning([]) do |d|
58
- argv.each_with_index do |arg, index|
56
+ config.argv.each_with_index do |arg, index|
59
57
  next if index == 0 && ignore_first_arg_on_command_line
60
58
  next if arg =~ /^(\w+) *=(.*)$/
61
59
  path = File.expand_path(arg)
@@ -74,7 +72,7 @@ module Chimps
74
72
  end
75
73
 
76
74
  def data_from_file
77
- [data_file ? YAML.load_file(data_file) : nil]
75
+ [config[:data_file] ? YAML.load_file(File.expand_path(config[:data_file])) : nil]
78
76
  end
79
77
 
80
78
  def data_from_stdin
@@ -86,12 +84,6 @@ module Chimps
86
84
  end
87
85
  end
88
86
 
89
- def define_data_options
90
- on_tail("-d", "--data-file PATH", "Path to a file containing key=value data") do |p|
91
- @data_file = File.expand_path(p)
92
- end
93
- end
94
-
95
87
  def ensure_data_is_present!
96
88
  raise CLIError.new("Must provide some data to send, either on the command line, from an input file, or by piping to STDIN. Try `chimps help #{name}'") unless data.present?
97
89
  end
@@ -197,7 +197,7 @@ module Chimps
197
197
  # @return [String]
198
198
  def default_archive_path
199
199
  # in current working directory...
200
- "chimps_#{dataset}-#{Time.now.strftime(Chimps::CONFIG[:timestamp_format])}.#{default_archive_extension}"
200
+ "chimps_#{dataset}-#{Time.now.strftime(Chimps::Config[:timestamp_format])}.#{default_archive_extension}"
201
201
  end
202
202
 
203
203
  # end <tt>zip</tt> if the data is less than 500 MB in size and
@@ -213,13 +213,13 @@ module Chimps
213
213
  #
214
214
  # @return [String]
215
215
  def readme_url
216
- File.join(Chimps::CONFIG[:site][:host], "/README-infochimps")
216
+ File.join(Chimps::Config[:site][:host], "/README-infochimps")
217
217
  end
218
218
 
219
219
  # The URL to the ICSS file for this dataset on Infochimps
220
220
  # servers
221
221
  def icss_url
222
- File.join(Chimps::CONFIG[:site][:host], "datasets", "#{dataset}.yaml")
222
+ File.join(Chimps::Config[:site][:host], "datasets", "#{dataset}.yaml")
223
223
  end
224
224
 
225
225
  # Both the local paths and remote paths to package.
@@ -34,7 +34,7 @@ module Chimps
34
34
  #
35
35
  # @return [Hash]
36
36
  def data
37
- { :package => {:fmt => token['fmt'], :pkg_size => bundler.size, :pkg_fmt => bundler.pkg_fmt, :summary => bundler.summary, :token_timestamp => token['timestamp'] } }
37
+ { :package => {:fmt => token['fmt'], :pkg_size => bundler.size, :pkg_fmt => bundler.pkg_fmt, :raw_summary => bundler.summary, :token_timestamp => token['timestamp'] } }
38
38
  end
39
39
 
40
40
  # Make a request to notify Infochimps of the new data.
data/lib/chimps.rb CHANGED
@@ -9,7 +9,6 @@ require 'chimps/utils'
9
9
  module Chimps
10
10
 
11
11
  autoload :Config, 'chimps/config'
12
- autoload :CONFIG, 'chimps/config'
13
12
  autoload :CLI, 'chimps/cli'
14
13
  autoload :Command, 'chimps/commands/base'
15
14
  autoload :Commands, 'chimps/commands'
@@ -18,5 +17,12 @@ module Chimps
18
17
  autoload :Response, 'chimps/response'
19
18
  autoload :Typewriter, 'chimps/typewriter'
20
19
  autoload :Workflows, 'chimps/workflows'
20
+
21
+ # Load and resolve configuration.
22
+ def self.boot!
23
+ Config.read Config[:site_config] if File.exist?(Config[:site_config])
24
+ Config.read Config[:config] if File.exist?(Config[:config])
25
+ Config.resolve!
26
+ end
21
27
 
22
28
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chimps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Dhruv Bansal
@@ -9,59 +15,87 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-07-02 00:00:00 -05:00
18
+ date: 2010-10-10 00:00:00 -05:00
13
19
  default_executable: chimps
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: rest-client
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 1
30
+ segments:
31
+ - 1
32
+ - 5
33
+ - 1
23
34
  version: 1.5.1
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: json
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 1
48
+ - 4
49
+ - 3
33
50
  version: 1.4.3
34
- version:
51
+ type: :runtime
52
+ version_requirements: *id002
35
53
  - !ruby/object:Gem::Dependency
36
54
  name: imw
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
40
58
  requirements:
41
59
  - - ">="
42
60
  - !ruby/object:Gem::Version
61
+ hash: 17
62
+ segments:
63
+ - 0
64
+ - 2
65
+ - 3
43
66
  version: 0.2.3
44
- version:
67
+ type: :runtime
68
+ version_requirements: *id003
45
69
  - !ruby/object:Gem::Dependency
46
70
  name: rspec
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
50
74
  requirements:
51
75
  - - ">="
52
76
  - !ruby/object:Gem::Version
77
+ hash: 13
78
+ segments:
79
+ - 1
80
+ - 2
81
+ - 9
53
82
  version: 1.2.9
54
- version:
83
+ type: :development
84
+ version_requirements: *id004
55
85
  - !ruby/object:Gem::Dependency
56
86
  name: yard
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
60
90
  requirements:
61
91
  - - ">="
62
92
  - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
63
96
  version: "0"
64
- version:
97
+ type: :development
98
+ version_requirements: *id005
65
99
  description: Chimps! allows you to easily make API calls against Infochimps web services. Chimps!'s Request and Response classes take care of all the details so you can remain calm and RESTful. Chimps! also comes with a command-line tool to make it simple to query, create, update, upload, and download data on Infochimps
66
100
  email: coders@infochimps.org
67
101
  executables:
@@ -117,9 +151,6 @@ files:
117
151
  - lib/chimps/workflows/upload/notifier.rb
118
152
  - lib/chimps/workflows/upload/token.rb
119
153
  - lib/chimps/workflows/upload/uploader.rb
120
- - spec/chimps/cli_spec.rb
121
- - spec/chimps/commands/base_spec.rb
122
- - spec/chimps/commands/list_spec.rb
123
154
  - spec/chimps/response_spec.rb
124
155
  - spec/chimps/typewriter_spec.rb
125
156
  - spec/chimps/workflows/upload/bundler_spec.rb
@@ -136,21 +167,27 @@ rdoc_options:
136
167
  require_paths:
137
168
  - lib
138
169
  required_ruby_version: !ruby/object:Gem::Requirement
170
+ none: false
139
171
  requirements:
140
172
  - - ">="
141
173
  - !ruby/object:Gem::Version
174
+ hash: 3
175
+ segments:
176
+ - 0
142
177
  version: "0"
143
- version:
144
178
  required_rubygems_version: !ruby/object:Gem::Requirement
179
+ none: false
145
180
  requirements:
146
181
  - - ">="
147
182
  - !ruby/object:Gem::Version
183
+ hash: 3
184
+ segments:
185
+ - 0
148
186
  version: "0"
149
- version:
150
187
  requirements: []
151
188
 
152
189
  rubyforge_project:
153
- rubygems_version: 1.3.5
190
+ rubygems_version: 1.3.7
154
191
  signing_key:
155
192
  specification_version: 3
156
193
  summary: Chimps! is a Ruby wrapper and command-line interface for the Infochimps APIs (http://infochimps.org/api, http://api.infochimps.com)
@@ -158,9 +195,6 @@ test_files:
158
195
  - spec/spec_helper.rb
159
196
  - spec/chimps/workflows/upload/bundler_spec.rb
160
197
  - spec/chimps/workflows/upload/token_spec.rb
161
- - spec/chimps/commands/base_spec.rb
162
- - spec/chimps/commands/list_spec.rb
163
198
  - spec/chimps/typewriter_spec.rb
164
- - spec/chimps/cli_spec.rb
165
199
  - spec/chimps/response_spec.rb
166
200
  - spec/support/custom_matchers.rb
@@ -1,22 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '../spec_helper')
2
-
3
- describe Chimps::CLI do
4
- end
5
-
6
- describe Chimps::CLI::Runner do
7
-
8
- it "should raise a CLIError when no command is given" do
9
- lambda { Chimps::CLI::Runner.new([]).execute! }.should raise_error(Chimps::CLIError)
10
- end
11
-
12
- it "should raise a CLIError when an unrecognized command is given" do
13
- lambda { Chimps::CLI::Runner.new(['foobar', 'arg1', 'arg2']).execute! }.should raise_error(Chimps::CLIError)
14
- end
15
-
16
- it "should recognize a command when given" do
17
- Chimps::Commands.should_receive(:construct).with('list', ['arg1', 'arg2'])
18
- Chimps::CLI::Runner.new(['list', 'arg1', 'arg2']).command # execute requires the command to be initialized and returned...
19
- end
20
-
21
- end
22
-
@@ -1,25 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '../../spec_helper')
2
-
3
- describe Chimps::Command do
4
-
5
- it "should return its full name" do
6
- Chimps::Command.name.should == "chimps::command"
7
- end
8
-
9
- it "should return just its command name" do
10
- Chimps::Command.new([]).name.should == "command"
11
- end
12
-
13
- it "should run any methods beginning with `define' and ending with `options?'" do
14
- klass = Class.new(Chimps::Command)
15
- klass.class_eval <<RUBY
16
- attr_accessor :test_property
17
- def define_test_options
18
- self.test_property=true
19
- end
20
- RUBY
21
- klass.new([]).test_property.should == true
22
- end
23
-
24
-
25
- end
@@ -1,25 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '../../spec_helper')
2
-
3
- describe Chimps::Commands::List do
4
-
5
- it "should return its full name" do
6
- Chimps::Command.name.should == "chimps::command"
7
- end
8
-
9
- it "should return just its command name" do
10
- Chimps::Command.new([]).name.should == "command"
11
- end
12
-
13
- it "should run any methods beginning with `define' and ending with `options?'" do
14
- klass = Class.new(Chimps::Command)
15
- klass.class_eval <<RUBY
16
- attr_accessor :test_property
17
- def define_test_options
18
- self.test_property=true
19
- end
20
- RUBY
21
- klass.new([]).test_property.should == true
22
- end
23
-
24
-
25
- end