adyen-admin 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzI5NzJjMjQ2ZGZlMWIyMTUxODBlNTJkYzg1ZjgyOGJjNDllMGQxYw==
4
+ OGVjODc0NDA1NzRiN2RlZDYyMDI4OGMwMTY0YWZmMDkxNDY2ODI0Ng==
5
5
  data.tar.gz: !binary |-
6
- YzQ1OGY5ZTZlN2RjOWRkZjRkZmJlMjY1YTc3ZGY4NjYxMjJkZjcyZA==
6
+ YmExZDNiMGZkMDBhZDU0OGM3M2EwY2VkN2JiZGZkMjViZjViOTkxMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OWRhZjM1NzExYzJiYzliNzk0Mzk4YWRhNDVjNWM0YWU5ODQzMWNmZWI2NjEy
10
- NWQ2NTRlMDU2NWNmZTM4YTc4OTc1ZTdkMjA2ZDg4Yzc2OGJlNzU2M2FmNjA4
11
- MTBhMTA1ZWRjNjU3ZTZlOGQ3YTkzYzcwZmU4NjNkMTg4YjdhMjk=
9
+ ZTQxZTYwMjkwODRlY2ZkMTdjMzNiNmVhNTZkM2RlNDlkNTI4OTM5MmYxZWRh
10
+ NTY1Y2U5MjE3YWEwN2M2ZWE0MjQ1NGYxOWUzYzE3Y2Y2ZDBlNTY2YWYwYTIy
11
+ OTEyYjMwNzI1NTBkMDFiZmI0YmJlZWUxZjc5NDFkZjBhMzAwZWQ=
12
12
  data.tar.gz: !binary |-
13
- OTE0MGI0MmM1NjY1NzljY2UyYmQzNzMyZTRkMGZlOTUxNjdmNzY3NGY3YmY3
14
- YmQ3MmVkZGQ3MzE0Y2IzM2NhODZkOThmOWE2Y2UzNjA2NDAyNjI1MWFjZTc5
15
- YjNmNDkzNzMyNmVkYzBlZmM3MmIzOTQ3ZmIzMWFjY2RlMDlhYzk=
13
+ MTYxNmRmN2VjNjBiZDU0NDA0MDJkMWJhMzNmNjUyMjNmMDg4OTk3NzAwZTQx
14
+ MGZkMmQyOTViOTQ0OWNjODNiY2EwMmNkMzIwY2FmMDA2YTg4NGU4ZjMzZWQ2
15
+ OTFiMzUyY2I5NDYzNGM5ZmEzN2YzMTU1ZDQ1NGY3ZDhiMTg0NmI=
data/CHANGES.md CHANGED
@@ -5,6 +5,11 @@
5
5
  * add CLI binaries (to compile + upload) -> read from .adyenrc file
6
6
  * make compatible with Live system
7
7
 
8
+ ## v0.0.18 - 16-11-2013
9
+ * include default_data in skin
10
+ * explicit path or code+name
11
+ * code cleanup
12
+
8
13
  ## v0.0.17 - 15-11-2013
9
14
  * fixed upload
10
15
  * gem updates
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.17
1
+ 0.0.18
@@ -17,91 +17,99 @@ module Adyen
17
17
  attr_reader :code, :name, :path
18
18
 
19
19
  def initialize(attributes = {})
20
- attributes.each do |key, value|
21
- send("#{key}=", value)
20
+ if attributes[:path] && attributes[:code]
21
+ raise ArgumentError, "Either :path or :code has to be provided"
22
22
  end
23
23
 
24
- self.path ||= File.expand_path File.join(Skin.default_path, [name,code].compact.join("-"))
25
- self.path ||= File.expand_path File.join(Skin.default_path, name.to_s)
26
- self.path ||= File.expand_path File.join(Skin.default_path, code.to_s)
27
-
28
- raise ArgumentError, "No Code given" unless code
24
+ if new_path = attributes[:path]
25
+ raise ArgumentError, ":path '#{new_path}' is not a valid skin" unless Skin.is_skin_path?(new_path)
26
+ @path = new_path
27
+ @code = skin_data[:code] || code_from_path(path)
28
+ @name = skin_data[:name] || name_from_path(path)
29
+ else
30
+ @code = attributes[:code]
31
+ raise ArgumentError, ":code is not provided" unless code
32
+ @name = attributes[:name]
33
+ @path = Skin.path_from_code(code) || Skin.generate_path(code, name)
34
+ end
29
35
  end
30
36
 
31
- def self.default_path
32
- @default_path || "."
33
- end
37
+ class << self
38
+ def default_path
39
+ @default_path || "."
40
+ end
34
41
 
35
- def self.default_path=(default_path)
36
- @default_path = default_path
37
- end
42
+ def default_path=(default_path)
43
+ @default_path = default_path
44
+ end
38
45
 
39
- # union remote and local skins. Local skins are frozen to
40
- # indicate no availble remote counter part which avoid update
41
- def self.all
42
- @all ||= {}.tap do |hash|
43
- if Adyen::Admin.authenticated?
44
- self.all_remote.each do |skin|
46
+ # union remote and local skins. Local skins are frozen to
47
+ # indicate no availble remote counter part which avoid update
48
+ def all
49
+ @all ||= {}.tap do |hash|
50
+ if Adyen::Admin.authenticated?
51
+ all_remote.each do |skin|
52
+ hash[skin.code] = skin unless hash[skin.code]
53
+ end
54
+ end
55
+ all_local.each do |skin|
45
56
  hash[skin.code] = skin unless hash[skin.code]
46
57
  end
58
+ end.values
59
+ end
60
+
61
+ # fetch all remote skins
62
+ def all_remote
63
+ page = Adyen::Admin.get(SKINS)
64
+ page.search(".data tbody tr").map do |node|
65
+ Skin.new({
66
+ :code => node.search("a")[0].content.strip,
67
+ :name => node.search("td")[1].content.strip,
68
+ })
47
69
  end
48
- self.all_local.each do |skin|
49
- hash[skin.code] = skin unless hash[skin.code]
50
- end
51
- end.values
52
- end
70
+ end
53
71
 
54
- # fetch all remote skins
55
- def self.all_remote
56
- page = Adyen::Admin.get(SKINS)
57
- page.search(".data tbody tr").map do |node|
58
- Skin.new({
59
- :code => node.search("a")[0].content.strip,
60
- :name => node.search("td")[1].content.strip,
61
- })
72
+ # fetch all local skins
73
+ def all_local
74
+ Dir[File.join(default_path.to_s, "*")].map do |skin_path|
75
+ Skin.new(:path => skin_path).freeze rescue nil
76
+ end.compact
62
77
  end
63
- end
64
78
 
65
- # fetch all local skins
66
- def self.all_local
67
- Dir[File.join(default_path.to_s, "*")].map do |skin_path|
68
- Skin.new(:path => skin_path).freeze rescue nil
69
- end.compact
70
- end
79
+ # find a skin within remote + local ones
80
+ def find(skin_code)
81
+ all.select do |skin|
82
+ skin.code == skin_code
83
+ end.first
84
+ end
71
85
 
72
- # find a skin within remote + local ones
73
- def self.find(skin_code)
74
- self.all.select do |skin|
75
- skin.code == skin_code
76
- end.first
77
- end
86
+ def purge_cache
87
+ @all = nil
88
+ end
78
89
 
79
- def self.purge_cache
80
- @all = nil
81
- end
90
+ def is_skin_path?(skin_path)
91
+ %w(skin.yml inc css js).any? do |sub_path|
92
+ File.exists?(File.join(skin_path.to_s, sub_path))
93
+ end
94
+ end
82
95
 
83
- ##################################
96
+ def path_from_code(code)
97
+ Dir[File.join(Skin.default_path, "**/*#{code}*")].first
98
+ end
84
99
 
85
- def path=(new_path)
86
- if Skin.is_skin_path?(new_path)
87
- @path = new_path
88
- if !skin_data.empty?
89
- self.code = skin_data[:code]
90
- self.name = skin_data[:name]
91
- else
92
- new_code, *new_name = File.basename(new_path).split("-").reverse
93
- self.code ||= new_code
94
- self.name ||= new_name.reverse.join("-")
95
- raise ArgumentError if self.code && self.code != new_code
96
- end
100
+ def generate_path(name, code)
101
+ dir_name = name.gsub(' ', '-').gsub(/[^a-z0-9-]/i, '')
102
+ File.expand_path File.join(Skin.default_path, [dir_name, code].compact.join("-"))
97
103
  end
98
104
  end
99
105
 
106
+ ##################################
107
+
100
108
  def get_file(filename)
101
- if self.path
102
- File.join(self.path, filename).tap do |file|
109
+ if path
110
+ File.join(path, filename).tap do |file|
103
111
  if !File.exists?(file)
104
- return File.join(File.dirname(self.path), parent_skin, filename)
112
+ return File.join(File.dirname(path), parent_skin, filename)
105
113
  end
106
114
  end
107
115
  end
@@ -140,13 +148,14 @@ module Adyen
140
148
 
141
149
  def update
142
150
  @skin_data = {
143
- :name => name,
144
- :code => code,
145
- :uploaded_at => Time.now,
146
- :version => remote_version,
151
+ :name => name,
152
+ :code => code,
153
+ :uploaded_at => Time.now.iso8601,
154
+ :version => remote_version,
147
155
  :version_live => remote_version(:live),
148
156
  :version_test => remote_version(:test),
149
157
  :parent_skin => parent_skin,
158
+ :default_data => default_data,
150
159
  }
151
160
  File.open(skin_data_file, "w") do |file|
152
161
  file.write @skin_data.to_yaml
@@ -163,7 +172,7 @@ module Adyen
163
172
 
164
173
  def decompile(filename, backup = true)
165
174
  # create backup of current, include any files
166
- if self.path
175
+ if path
167
176
  if backup
168
177
  compress(/(zip|lock)$/, ".backup.zip")
169
178
  end
@@ -175,7 +184,7 @@ module Adyen
175
184
 
176
185
  Zip::File.open(filename) do |zip_file|
177
186
  zip_file.each do |file|
178
- f_path = File.join(self.path || decompile_path, file.name.gsub("#{code}/", ""))
187
+ f_path = File.join(path || decompile_path, file.name.gsub("#{code}/", ""))
179
188
  FileUtils.mkdir_p(File.dirname(f_path))
180
189
  if File.directory?(f_path)
181
190
  `mkdir -p #{f_path}`
@@ -188,12 +197,12 @@ module Adyen
188
197
  self.path ||= decompile_path
189
198
 
190
199
  if backup
191
- `mv .backup.zip #{File.join(self.path, ".backup.zip")}`
200
+ `mv .backup.zip #{File.join(path, ".backup.zip")}`
192
201
  end
193
202
  end
194
203
 
195
204
  def compile(output, pattern = /<!-- ### inc\/([a-z]+) -->(.+?)<!-- ### -->/m)
196
- raise ArgumentError, "No Path given" unless self.path
205
+ raise ArgumentError, "No Path given" unless path
197
206
 
198
207
  output.scan(pattern) do |name, content|
199
208
  file = File.join(path, "inc/#{name}.txt")
@@ -232,7 +241,7 @@ module Adyen
232
241
 
233
242
  # http://stackoverflow.com/questions/3420587/ruby-mechanize-multipart-form-with-file-upload-to-a-mediawiki
234
243
  def upload
235
- file = self.compress
244
+ file = compress
236
245
 
237
246
  page = Adyen::Admin.get(UPLOAD_SELECT)
238
247
  page = page.link_with(:href => Regexp.new(Regexp.escape(UPLOAD % code))).click
@@ -264,33 +273,26 @@ module Adyen
264
273
  end
265
274
 
266
275
  def to_s
267
- self.code
276
+ code
268
277
  end
269
278
 
270
279
  def ==(skin)
271
- self.code == skin.code
280
+ code == skin.code
272
281
  end
273
282
 
274
- protected
275
- def code=(c)
276
- @code = c
283
+ private
284
+ def code_from_path(path)
285
+ File.basename(path).split("-").last
277
286
  end
278
287
 
279
- def name=(n)
280
- @name = n
288
+ def name_from_path(path)
289
+ File.basename(path).split("-")[0..-2].join('-')
281
290
  end
282
291
 
283
292
  def skin_data_file
284
293
  File.join(path, 'skin.yml')
285
294
  end
286
295
 
287
- def self.is_skin_path?(skin_path)
288
- %w(skin.html.erb skin.yml inc css js).each do |sub_path|
289
- return true if File.exists?(File.join(skin_path.to_s, sub_path))
290
- end
291
- false
292
- end
293
-
294
296
  def nested_subdirectory?(skin_path, file)
295
297
  (file.count("/") - skin_path.count("/")) > 2
296
298
  end
@@ -16,6 +16,10 @@ module Adyen::Admin
16
16
  end
17
17
  end
18
18
 
19
+ before do
20
+ Adyen::Admin::Skin.default_path = skin_fixtures
21
+ end
22
+
19
23
  describe ".all" do
20
24
  it 'returns all local skins' do
21
25
  Skin.all.should == Skin.all_local
@@ -42,7 +46,6 @@ module Adyen::Admin
42
46
  end
43
47
 
44
48
  it 'sets local path' do
45
- Adyen::Admin::Skin.default_path = skin_fixtures
46
49
  Skin.find(skin_code).path.should == "#{skin_fixtures}/example-#{skin_code}"
47
50
  end
48
51
  end
@@ -134,11 +137,11 @@ module Adyen::Admin
134
137
  let(:skin) { Skin.new(:path => path) }
135
138
 
136
139
  it "sets name" do
137
- skin.name.should == "DV3tf95f"
140
+ skin.name.should == "custom name"
138
141
  end
139
142
 
140
143
  it "sets code" do
141
- skin.code.should == "customCode"
144
+ skin.code.should == "DV3tf95f"
142
145
  end
143
146
 
144
147
  it "sets version_live" do
@@ -165,7 +168,7 @@ module Adyen::Admin
165
168
  end
166
169
 
167
170
  it "sets version_live" do
168
- skin.path.should == "#{skin_fixtures}/DV3tf95f"
171
+ skin.path.should == "#{skin_fixtures}/customCode-DV3tf95f"
169
172
  end
170
173
  end
171
174
  end
@@ -173,10 +176,7 @@ module Adyen::Admin
173
176
 
174
177
  describe "#update" do
175
178
  let(:path) { "#{skin_fixtures}/example-#{skin_code}" }
176
-
177
- before do
178
- skin.path = path
179
- end
179
+ let(:skin) { Skin.new(:path => path) }
180
180
 
181
181
  after do
182
182
  `rm -f #{path}/skin.yml`
@@ -413,9 +413,7 @@ module Adyen::Admin
413
413
  end
414
414
 
415
415
  context "valid set" do
416
- before do
417
- skin.path = path
418
- end
416
+ let(:skin) { Skin.new(:path => path) }
419
417
 
420
418
  it "increases version" do
421
419
  expect { subject }.to change { skin.send(:remote_version) }.by(1)
@@ -1,6 +1,6 @@
1
1
  ---
2
- :name: DV3tf95f
3
- :code: customCode
2
+ :name: custom name
3
+ :code: DV3tf95f
4
4
  :uploaded_at:
5
5
  :version: 12
6
6
  :version_test: 3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adyen-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Bielohlawek