shopifydev 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rails/tasks/shops.rake +7 -2
- data/lib/shopifydev/pry/commands.rb +84 -24
- data/lib/shopifydev/version.rb +1 -1
- metadata +3 -3
data/lib/rails/tasks/shops.rake
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
desc "Outputs list of shops that have installed the app"
|
2
2
|
task :shops => :environment do
|
3
|
-
url_column =
|
4
|
-
|
3
|
+
url_column = 'myshopify_domain'
|
4
|
+
url_column = 'domain' unless Shop.column_names.include?(url_column)
|
5
|
+
url_column = 'url' unless Shop.column_names.include?(url_column)
|
6
|
+
json = {
|
7
|
+
shops: Shop.select("id,#{url_column},token").all.map(&:attributes),
|
8
|
+
url_column: url_column
|
9
|
+
}.to_json
|
5
10
|
puts "----snip----"
|
6
11
|
puts json
|
7
12
|
end
|
@@ -4,7 +4,7 @@ require 'oj'
|
|
4
4
|
class Switch
|
5
5
|
def initialize
|
6
6
|
@current_shop = ''
|
7
|
-
|
7
|
+
reset!
|
8
8
|
end
|
9
9
|
|
10
10
|
def current_shop
|
@@ -12,8 +12,17 @@ class Switch
|
|
12
12
|
Color.green{ "current shop:"} + " #{@current_shop}"
|
13
13
|
end
|
14
14
|
|
15
|
-
def reset
|
15
|
+
def reset!
|
16
16
|
@menu = default_menu
|
17
|
+
@finished = false
|
18
|
+
end
|
19
|
+
|
20
|
+
def finished?
|
21
|
+
@finished
|
22
|
+
end
|
23
|
+
|
24
|
+
def finish!
|
25
|
+
@finished = true
|
17
26
|
end
|
18
27
|
|
19
28
|
def menu
|
@@ -64,14 +73,18 @@ class Switch
|
|
64
73
|
def handle_choice
|
65
74
|
result = ''
|
66
75
|
|
67
|
-
case @cfg
|
68
|
-
when
|
76
|
+
case @cfg
|
77
|
+
when String then
|
69
78
|
case @breadcrumbs[1].to_sym
|
70
79
|
when :development then menu_method = self.method(:development_menu)
|
71
80
|
when :heroku then menu_method = self.method(:heroku_menu)
|
72
81
|
else menu_method = self.method(:missing_menu)
|
73
82
|
end
|
74
|
-
|
83
|
+
when Hash
|
84
|
+
result = handle_by_shop_type
|
85
|
+
finish!
|
86
|
+
else
|
87
|
+
raise "don't know what to do with @cfg: #{@cfg.inspect}"
|
75
88
|
end
|
76
89
|
|
77
90
|
if menu_method
|
@@ -84,17 +97,18 @@ class Switch
|
|
84
97
|
|
85
98
|
def handle_by_shop_type
|
86
99
|
if @cfg.keys.include?("shop_type")
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
100
|
+
case @cfg["shop_type"].to_sym
|
101
|
+
when :local
|
102
|
+
session = ShopifyAPI::Session.new(@cfg['url'], @cfg['token'])
|
103
|
+
session.valid? # returns true
|
104
|
+
ShopifyAPI::Base.activate_session(session)
|
105
|
+
when :heroku
|
106
|
+
puts Color.red{ "can't handle heroku yet"}
|
107
|
+
end
|
92
108
|
else
|
93
109
|
set_shop(@cfg[:api_key], @cfg[:password], @cfg[:myshopify_domain])
|
94
|
-
result = self.current_shop
|
95
110
|
end
|
96
|
-
|
97
|
-
result
|
111
|
+
self.current_shop
|
98
112
|
end
|
99
113
|
|
100
114
|
def default_menu
|
@@ -112,8 +126,9 @@ class Switch
|
|
112
126
|
# TODO this method is pretty obscure
|
113
127
|
def development_menu
|
114
128
|
# this needs to be memoized
|
115
|
-
|
116
|
-
|
129
|
+
@apps ||= {}
|
130
|
+
@apps[@cfg] ||= LocalShopifyApp.new(@cfg)
|
131
|
+
shops = @apps[@cfg].shops
|
117
132
|
|
118
133
|
# add the shop_type to the array of shops
|
119
134
|
shops.each do |shop|
|
@@ -126,6 +141,8 @@ class Switch
|
|
126
141
|
# iterate over shopifydev.yaml and replace the local file path matching
|
127
142
|
# domain with the list of shops associated with that domain
|
128
143
|
# TODO drop M's terrible habbit of using k and v for key and value
|
144
|
+
|
145
|
+
# TODO: use detect
|
129
146
|
shopify_config["apps"]["development"].each do |k, v|
|
130
147
|
if v == domain
|
131
148
|
shopify_config["apps"]["development"][k] = shops
|
@@ -174,11 +191,41 @@ class HerokuShopifyApp < ShopifyAppShopList
|
|
174
191
|
end
|
175
192
|
|
176
193
|
class LocalShopifyApp < ShopifyAppShopList
|
194
|
+
def refresh!
|
195
|
+
@data = nil
|
196
|
+
end
|
197
|
+
|
198
|
+
def url_column
|
199
|
+
data['url_column']
|
200
|
+
end
|
201
|
+
|
177
202
|
def shops
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
203
|
+
data['shops']
|
204
|
+
end
|
205
|
+
|
206
|
+
def data
|
207
|
+
@data ||= begin
|
208
|
+
data = {}
|
209
|
+
if Pathname(path).expand_path == Pathname.getwd
|
210
|
+
url_column = 'myshopify_domain'
|
211
|
+
url_column = 'domain' unless ::Shop.column_names.include?(url_column)
|
212
|
+
url_column = 'url' unless ::Shop.column_names.include?(url_column)
|
213
|
+
data = {
|
214
|
+
'shops' => ::Shop.select("id,#{url_column},token").all.map(&:attributes),
|
215
|
+
'url_column' => url_column
|
216
|
+
}
|
217
|
+
else
|
218
|
+
json = `/bin/bash -l -c "unset BUNDLE_GEMFILE; cd #{path} 2> /dev/null; bundle exec rake shops 2>/dev/null"`
|
219
|
+
json = json.split("----snip----\n").last
|
220
|
+
json = json.split("\n").last
|
221
|
+
data = Oj.load(json)
|
222
|
+
# TODO: this should go away when we refactor into objects, since the app object will know what it's url_column is and be responsible for shop data
|
223
|
+
end
|
224
|
+
unless data['url_column'] == 'url'
|
225
|
+
data['shops'].each{|shop| shop['url'] = shop[data['url_column']]}
|
226
|
+
end
|
227
|
+
data
|
228
|
+
end
|
182
229
|
end
|
183
230
|
end
|
184
231
|
|
@@ -229,6 +276,9 @@ class ConfigMenu
|
|
229
276
|
|
230
277
|
header("Local Apps")
|
231
278
|
json[:apps][:development].each do |k, path|
|
279
|
+
if Pathname(path).expand_path == Pathname.getwd
|
280
|
+
path = Color.green{ path }
|
281
|
+
end
|
232
282
|
choice([:apps, :development, k], path)
|
233
283
|
end
|
234
284
|
|
@@ -287,11 +337,21 @@ shopifydev_command_set = Pry::CommandSet.new do
|
|
287
337
|
|
288
338
|
case true
|
289
339
|
when args.empty?
|
290
|
-
_pry_.switch.reset # reset to the first menu page
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
340
|
+
_pry_.switch.reset! # reset to the first menu page
|
341
|
+
result = ''
|
342
|
+
until _pry_.switch.finished?
|
343
|
+
output.puts _pry_.switch.menu.print
|
344
|
+
print "❔ " + Color.yellow
|
345
|
+
choice = $stdin.gets
|
346
|
+
print Color.clear
|
347
|
+
if choice.blank?
|
348
|
+
_pry_.switch.reset!
|
349
|
+
else
|
350
|
+
result = _pry_.switch.pick(choice.chomp.to_i)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
puts result
|
354
|
+
_pry_.switch.reset!
|
295
355
|
when (args.length == 1)
|
296
356
|
ix = args.first.to_i
|
297
357
|
output.puts _pry_.switch.pick(ix)
|
data/lib/shopifydev/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopifydev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -250,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
250
250
|
version: '0'
|
251
251
|
segments:
|
252
252
|
- 0
|
253
|
-
hash:
|
253
|
+
hash: 2813767697343039389
|
254
254
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
255
255
|
none: false
|
256
256
|
requirements:
|
@@ -259,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
259
|
version: '0'
|
260
260
|
segments:
|
261
261
|
- 0
|
262
|
-
hash:
|
262
|
+
hash: 2813767697343039389
|
263
263
|
requirements: []
|
264
264
|
rubyforge_project:
|
265
265
|
rubygems_version: 1.8.25
|