insup 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ddabfbd03d3ec5598cf705493a8dbd48aeb1d3d
4
- data.tar.gz: 511d852bd1c4cd25bb6214b22fff66b3f06655da
3
+ metadata.gz: 50dd77c58e2d1a3ce04bd92d4d7bc9c2d22f4af3
4
+ data.tar.gz: 1dcacbe9f405205fa16c3f8a827b96f934fb96d7
5
5
  SHA512:
6
- metadata.gz: 9ebc75e74472e577ac81b3cec28c882a3b3b23f294f540c8d8cb60b793728271b45a14bd04046be164ec899b635c7c95408d849af6babdd4d1a3856b5351b51b
7
- data.tar.gz: 3cda1702f037ffc0efbccbeb73d353f37683b78b030b821ca64a3b40c32ce03afca0072a5413b8e468e7cb493c00d5c775a81956e0e09129cde754423ae30a77
6
+ metadata.gz: 4ab17cb95225f9787d1fde6b20b20e5e4edecb93235ba584ed706b99ee15f786362747abb57b88109ca70b36baa320d89b13655828fbea2af85a188f9fbebf69
7
+ data.tar.gz: 95dbbdbd6fe84c8f10ff9799e61610dd5eb9b002266827e1e971d2ebc2178f4668aaeccfa334a907627bd7e3fad11fcf52ed1784a4f1bf0d519ba2e7b98b18f5
data/.gitignore CHANGED
@@ -3,6 +3,7 @@ vendor/bundle
3
3
  .bundle
4
4
  .irb-history
5
5
  .insup
6
+ *.swp
6
7
  log
7
8
 
8
9
  /.tags*
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.1
3
+ - 2.1.2
4
4
  - 1.9.3
5
5
  install: "bundle install --path vendor/bundle"
6
6
  cache:
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- insup (0.1.2)
4
+ insup (0.3)
5
5
  activeresource (~> 4.0)
6
6
  colorize (~> 0.7)
7
- gli (~> 2.10)
7
+ gli (~> 2.11)
8
8
  listen (~> 2.7)
9
9
  match_files (~> 0.2)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activemodel (4.1.1)
15
- activesupport (= 4.1.1)
14
+ activemodel (4.1.4)
15
+ activesupport (= 4.1.4)
16
16
  builder (~> 3.1)
17
17
  activeresource (4.0.0)
18
18
  activemodel (~> 4.0)
19
19
  activesupport (~> 4.0)
20
20
  rails-observers (~> 0.1.1)
21
- activesupport (4.1.1)
21
+ activesupport (4.1.4)
22
22
  i18n (~> 0.6, >= 0.6.9)
23
23
  json (~> 1.7, >= 1.7.7)
24
24
  minitest (~> 5.1)
@@ -35,38 +35,40 @@ GEM
35
35
  term-ansicolor
36
36
  thor
37
37
  diff-lcs (1.2.5)
38
- docile (1.1.3)
38
+ docile (1.1.5)
39
39
  ffi (1.9.3)
40
- gli (2.10.0)
41
- i18n (0.6.9)
40
+ gli (2.11.0)
41
+ i18n (0.6.11)
42
42
  json (1.8.1)
43
- listen (2.7.6)
43
+ listen (2.7.9)
44
44
  celluloid (>= 0.15.2)
45
45
  rb-fsevent (>= 0.9.3)
46
46
  rb-inotify (>= 0.9)
47
47
  match_files (0.2)
48
48
  mime-types (2.3)
49
- minitest (5.3.4)
49
+ minitest (5.4.0)
50
50
  multi_json (1.10.1)
51
+ netrc (0.7.7)
51
52
  rails-observers (0.1.2)
52
53
  activemodel (~> 4.0)
53
54
  rb-fsevent (0.9.4)
54
- rb-inotify (0.9.4)
55
+ rb-inotify (0.9.5)
55
56
  ffi (>= 0.5.0)
56
- rest-client (1.6.7)
57
- mime-types (>= 1.16)
57
+ rest-client (1.7.1)
58
+ mime-types (>= 1.16, < 3.0)
59
+ netrc (~> 0.7)
58
60
  rspec (3.0.0)
59
61
  rspec-core (~> 3.0.0)
60
62
  rspec-expectations (~> 3.0.0)
61
63
  rspec-mocks (~> 3.0.0)
62
- rspec-core (3.0.0)
64
+ rspec-core (3.0.2)
63
65
  rspec-support (~> 3.0.0)
64
- rspec-expectations (3.0.0)
66
+ rspec-expectations (3.0.2)
65
67
  diff-lcs (>= 1.2.0, < 2.0)
66
68
  rspec-support (~> 3.0.0)
67
- rspec-mocks (3.0.0)
69
+ rspec-mocks (3.0.2)
68
70
  rspec-support (~> 3.0.0)
69
- rspec-support (3.0.0)
71
+ rspec-support (3.0.2)
70
72
  simplecov (0.8.2)
71
73
  docile (~> 1.1.0)
72
74
  multi_json
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/insup.svg)](http://badge.fury.io/rb/insup)
5
5
  [![Coverage Status](https://coveralls.io/repos/httplab/insup/badge.png)](https://coveralls.io/r/httplab/insup)
6
6
  [![Code Climate](https://codeclimate.com/github/httplab/insup.png)](https://codeclimate.com/github/httplab/insup)
7
- [![Dependency Status](https://gemnasium.com/httplab/insup.svg)](https://gemnasiurm.com/httplab/insup)
7
+ [![Dependency Status](https://gemnasium.com/httplab/insup.svg)](https://gemnasium.com/httplab/insup)
8
8
 
9
9
  ## Description
10
10
 
@@ -45,9 +45,9 @@ Currently there are two trackers available:
45
45
 
46
46
  Currently there are two uploaders available:
47
47
 
48
- * **Insales uploader** will upload files to the specified Insales theme. Specify `Insup::Uploader::Insales` or `insales` in the `class` section of the uploader configuration. Insales uploader also requires `theme_id` to be specified. Working directory should include 3 subfolders *media*, *snippets* and *templates*. The same 3 folders should be specified in the `track` sectio of .insup file.
48
+ * **Insales uploader** will upload files to the specified Insales theme. Specify `Insup::Uploader::InsalesUploader` or `insales` in the `class` section of the uploader configuration. Insales uploader also requires `theme_id` to be specified. Working directory should include 3 subfolders *media*, *snippets* and *templates*. The same 3 folders should be specified in the `track` sectio of .insup file.
49
49
 
50
- * **Dummy uploader** will only print its operations to the console without actually uploading anything. It can be used for testing the configuration. Use by specifying `dummy` or `Insup::Uploader::Dummy` in the `class` section.
50
+ * **Dummy uploader** will only print its operations to the console without actually uploading anything. It can be used for testing the configuration. Use by specifying `dummy` or `Insup::Uploader::DummyUploader` in the `class` section.
51
51
 
52
52
  ### Operation modes
53
53
 
@@ -78,6 +78,11 @@ Upload changes
78
78
  ```bash
79
79
  insup commit
80
80
  ```
81
+ You can also specify particlular files with the `commit` command:
82
+ ```bash
83
+ insup commit [file1 [file2 [file3 [...]]]]
84
+ ```
85
+ In this case **tracking info is ignored** and each file specified is treated as modified or deleted (if it doesn't actually exist).
81
86
 
82
87
  ### Other commands
83
88
  List all themes in the Insales shop if `insales` section is given in the .insup file:
@@ -85,6 +90,12 @@ List all themes in the Insales shop if `insales` section is given in the .insup
85
90
  insup insales list-themes
86
91
  ```
87
92
 
93
+ Download all Insales theme files into the working directory:
94
+ ```bash
95
+ insup insales download [-f] [-t theme-id]
96
+ ```
97
+ Specify `-f` flag to overwrite any existing file. If no theme ID is specified Insup will download theme specified in the .insup file.
98
+
88
99
  List files under tracked locations:
89
100
  ```bash
90
101
  insup list-files [--all|--ignored]
data/bin/insup CHANGED
@@ -21,6 +21,7 @@ pre do |global_options, command, options, args|
21
21
  end
22
22
 
23
23
  on_error do |ex|
24
+ puts ex.message
24
25
  Insup::Console.process_error(ex)
25
26
  false
26
27
  end
@@ -85,7 +86,7 @@ command :listen do |c|
85
86
  end
86
87
  end
87
88
 
88
- desc 'Tasks related to insales'
89
+ desc 'Tasks related to Insales'
89
90
  command :insales do |c|
90
91
  c.default_command 'list-themes'
91
92
  c.desc 'List themes in the current Insales shop'
@@ -94,6 +95,15 @@ command :insales do |c|
94
95
  Insup::Console.insales_list_themes
95
96
  end
96
97
  end
98
+
99
+ c.desc 'Download theme files to current directory'
100
+ c.command 'download' do |sc|
101
+ sc.switch [:f, :force], desc: 'Overwrite existing files without prompt'
102
+ sc.flag [:t, :theme], desc: 'Insales theme id', default_value: nil
103
+ sc.action do |global_options, options, args|
104
+ Insup::Console.insales_download_theme(options[:force], options[:theme])
105
+ end
106
+ end
97
107
  end
98
108
 
99
109
  default_command :listen
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.license = 'MIT'
15
15
 
16
16
  s.add_dependency 'colorize', '~> 0.7'
17
- s.add_dependency 'gli', '~> 2.10'
17
+ s.add_dependency 'gli', '~> 2.11'
18
18
  s.add_dependency 'listen', '~> 2.7'
19
19
  s.add_dependency 'match_files', '~> 0.2'
20
20
  s.add_dependency 'activeresource', '~> 4.0'
@@ -4,9 +4,15 @@ track:
4
4
  - snippets
5
5
  - templates
6
6
 
7
+ # Tracker settings
8
+ # class: tracker class. Use 'git' or 'simple'
7
9
  tracker:
8
10
  class: git
9
11
 
12
+ # Insales settings
13
+ # subdomain: your Insales subdomain, e.g. my-shop.myinsales.ru
14
+ # api_key: Insales API key for insup application
15
+ # password: Insales API passeword for insup application
10
16
  insales:
11
17
  subdomain:
12
18
  api_key:
@@ -14,6 +20,7 @@ insales:
14
20
 
15
21
  # Uploader settings
16
22
  # class: uploader class. Use 'insales' or 'dummy'
23
+ # theme_id: Insales theme ID
17
24
  uploader:
18
25
  class: insales
19
26
  theme_id:
@@ -30,14 +37,14 @@ ignore:
30
37
  - '*.log'
31
38
 
32
39
  # Logging settings
33
- # file: Path to the log file relative to the working directory
34
- # level: Log error level. Available options are 'unknown', 'debug', 'error', 'fatal', 'info',
35
- # and 'warn'
36
- # pattern: A pattern to for logger to use when writing messages. Available substitutions are:
37
- # %{timestamp}, %{level} and %{message}
40
+ # file: path to the log file relative to the working directory. Omit this key to use STDERR instead
41
+ # of file.
42
+ # level: log error level. Available options are 'unknown', 'debug', 'error', 'fatal', 'info',
43
+ # and 'warn'.
44
+ # pattern: a pattern to for logger to use when writing messages. Available substitutions are:
45
+ # %{timestamp}, %{level}, %{message} and %{backtrace}.
38
46
  #
39
-
40
47
  log:
41
48
  file: 'log/insup.log'
42
49
  level: 'info'
43
- pattern: "%{timestamp} - %{level}\t: %{message}\n"
50
+ pattern: "%{timestamp} - %{level}\t: %{message} %{backtrace}\n"
@@ -20,7 +20,8 @@ class Insup
20
20
  def self.create_insup_file(dir = nil)
21
21
  dir ||= Dir.getwd
22
22
  template_file = File.join(File.dirname(File.expand_path(__FILE__)), '../insup.template')
23
- FileUtils.cp(template_file, File.join(dir, '.insup'))
23
+ path = File.join(dir, '.insup')
24
+ FileUtils.cp(template_file, path) if !File.exist?(path)
24
25
  end
25
26
 
26
27
  def tracked_locations
@@ -58,7 +59,7 @@ class Insup
58
59
  klass = Insup::Uploader.find_uploader(uploader_conf['class']) || Object::const_get(uploader_conf['class'])
59
60
  klass.new(@settings)
60
61
  else
61
- Uploader::Dummy.new(@settings)
62
+ Uploader::DummyUploader.new(@settings)
62
63
  end
63
64
  end
64
65
 
@@ -81,10 +82,13 @@ class Insup
81
82
 
82
83
  def listen
83
84
  @listener = Listener.new(@base, @settings)
84
-
85
85
  @listener.listen do |changes|
86
- changes.each do |change|
87
- uploader.process_file(change)
86
+ begin
87
+ changes.each do |change|
88
+ uploader.process_file(change)
89
+ end
90
+ rescue Exceptions::RecoverableUploaderError => ex
91
+ logger.error(ex)
88
92
  end
89
93
  end
90
94
  end
@@ -1,5 +1,6 @@
1
1
  require 'colorize'
2
2
  require 'fileutils'
3
+ require 'io/console'
3
4
  require_relative '../insup'
4
5
 
5
6
  module Insup::Console
@@ -71,6 +72,25 @@ module Insup::Console
71
72
  end
72
73
  end
73
74
 
75
+ def self.insales_download_theme(force = false, theme_id = nil)
76
+ theme_id ||= @settings.uploader['theme_id']
77
+ puts "Downloading theme #{theme_id}"
78
+
79
+ @insup.insales.download_theme(theme_id, Dir.getwd) do |asset, exists|
80
+ if exists && !force
81
+ puts "#{asset.path} already exists"
82
+ false
83
+ else
84
+ if exists
85
+ puts "Overwriting #{asset.path}"
86
+ else
87
+ puts "Downloading #{asset.path}"
88
+ end
89
+ true
90
+ end
91
+ end
92
+ end
93
+
74
94
  def self.status
75
95
  @insup.changes.each do |x|
76
96
  case x.state
@@ -101,7 +121,7 @@ module Insup::Console
101
121
  Kernel.trap( "INT" ) { exit_requested = true }
102
122
 
103
123
  while !exit_requested do
104
- sleep 0.1
124
+ sleep(0.1)
105
125
  end
106
126
 
107
127
  puts 'Stopping listener...'
@@ -1,5 +1,7 @@
1
1
  module Insup::Exceptions
2
2
  InsupError = Class.new(StandardError)
3
3
  UploaderError = Class.new(InsupError)
4
+ RecoverableUploaderError = Class.new(UploaderError)
5
+ FatalUploaderError = Class.new(UploaderError)
4
6
  NotAGitRepositoryError = Class.new(InsupError)
5
7
  end
@@ -1,5 +1,7 @@
1
- class Insup::Insales
1
+ require 'net/http'
2
+ require 'json'
2
3
 
4
+ class Insup::Insales
3
5
  def initialize(settings)
4
6
  @settings = settings
5
7
  end
@@ -27,9 +29,25 @@ class Insup::Insales
27
29
  @settings.insales
28
30
  end
29
31
 
30
- def print_config
31
-
32
+ def download_theme(theme_id, dir)
33
+ configure_api
34
+ theme = Theme.find(theme_id)
35
+
36
+ theme.assets.each do |asset|
37
+ next if !asset.dirname
38
+ path = File.join(dir, asset.path)
39
+ exists = File.exist?(path)
40
+ write = !exists
41
+ write = yield(asset, exists) if block_given?
42
+
43
+ if write
44
+ File.delete(path) if exists
45
+ Dir.mkdir(File.dirname(path)) if !Dir.exist?(File.dirname(path))
46
+ File.open(path, 'wb'){|f| f.write(asset.data)}
47
+ end
48
+ end
32
49
  end
50
+
33
51
  end
34
52
 
35
53
  require 'active_resource'
@@ -1,5 +1,68 @@
1
+ require 'base64'
2
+ require 'net/http'
1
3
  class Insup::Insales::Asset < Insup::Insales::Base
2
4
  belongs_to :theme, class_name: 'Insup::Insales::Theme'
3
5
 
4
6
  self.prefix = '/admin/themes/:theme_id/'
7
+
8
+ TYPE_MAP = {
9
+ 'media' => 'Asset::Media',
10
+ 'snippets' => 'Asset::Snippet',
11
+ 'templates' => 'Asset::Template',
12
+ 'config' => 'Asset::Configuration'
13
+ }.freeze
14
+
15
+ def filename
16
+ fname_rex = /\..*+$/
17
+ if name.match(fname_rex)
18
+ name
19
+ elsif human_readable_name.match(fname_rex)
20
+ human_readable_name
21
+ else
22
+ nil
23
+ end
24
+ end
25
+
26
+ def is_image?
27
+ content_type =~ /image/ || content_type =~ /octet-stream/ || content_type =~ /flash/
28
+ end
29
+
30
+ def self.get_type(path)
31
+ TYPE_MAP.each do |k,v|
32
+ return v if path.start_with?("#{k}/")
33
+ end
34
+ end
35
+
36
+ def dirname
37
+ TYPE_MAP.invert[type]
38
+ end
39
+
40
+ def path
41
+ "#{dirname}/#{filename}"
42
+ end
43
+
44
+ def data
45
+ if respond_to? (:asset_url)
46
+ download_data_from_url
47
+ elsif ['Asset::Snippet', 'Asset::Template'].include?(type)
48
+ w = get_full
49
+ w.content if w.respond_to?(:content)
50
+ end
51
+ end
52
+
53
+ def theme_id
54
+ prefix_options[:theme_id]
55
+ end
56
+
57
+ def get_full
58
+ self.class.find(id, params: {theme_id: theme_id})
59
+ end
60
+
61
+ def url
62
+ "#{self.class.site}#{self.asset_url}"
63
+ end
64
+
65
+ def download_data_from_url
66
+ Net::HTTP.get(URI(self.url))
67
+ end
5
68
  end
@@ -27,35 +27,14 @@ class Listener
27
27
 
28
28
  res = []
29
29
 
30
- flags.each do |f, flags|
30
+ flags.each do |f, flag|
31
31
  pn = Pathname.new(f)
32
32
  basepn = Pathname.new(@base)
33
33
  file = pn.relative_path_from(basepn).to_s
34
-
35
34
  next if ignore_matcher.matched?(file)
36
-
37
- case flags
38
- when 1
39
- res << Insup::TrackedFile.new(file, Insup::TrackedFile::DELETED)
40
- when 2
41
- res << Insup::TrackedFile.new(file, Insup::TrackedFile::MODIFIED)
42
- when 3
43
- res << Insup::TrackedFile.new(file, Insup::TrackedFile::DELETED)
44
- when 4
45
- res << Insup::TrackedFile.new(file, Insup::TrackedFile::NEW)
46
- when 5
47
- if File.exist?(file)
48
- res << Insup::TrackedFile.new(file, Insup::TrackedFile::UNSURE)
49
- end
50
- when 6
51
- res << Insup::TrackedFile.new(file, Insup::TrackedFile::NEW)
52
- when 7
53
- if File.exist?(file)
54
- res << Insup::TrackedFile.new(file, Insup::TrackedFile::UNSURE)
55
- end
56
- end
35
+ tracked_file = create_tracked_file(flag, file)
36
+ res << tracked_file if !tracked_file.nil?
57
37
  end
58
-
59
38
  yield res
60
39
  end
61
40
 
@@ -70,6 +49,30 @@ class Listener
70
49
 
71
50
  protected
72
51
 
52
+ def create_tracked_file(flags, file)
53
+ case flags
54
+ when 1
55
+ Insup::TrackedFile.new(file, Insup::TrackedFile::DELETED)
56
+ when 2
57
+ Insup::TrackedFile.new(file, Insup::TrackedFile::MODIFIED)
58
+ when 3
59
+ Insup::TrackedFile.new(file, Insup::TrackedFile::DELETED)
60
+ when 4
61
+ Insup::TrackedFile.new(file, Insup::TrackedFile::NEW)
62
+ when 5
63
+ if File.exist?(file)
64
+ Insup::TrackedFile.new(file, Insup::TrackedFile::UNSURE)
65
+ end
66
+ when 6
67
+ Insup::TrackedFile.new(file, Insup::TrackedFile::NEW)
68
+ when 7
69
+ if File.exist?(file)
70
+ Insup::TrackedFile.new(file, Insup::TrackedFile::UNSURE)
71
+ end
72
+ end
73
+
74
+ end
75
+
73
76
  def ignore_matcher
74
77
  @ignore_matcher ||= ::MatchFiles.git(@base, ignore_patterns)
75
78
  end
@@ -2,10 +2,9 @@ require_relative('../git')
2
2
 
3
3
  # Git tracker: tracks files by evaluating changes in Git repo
4
4
  class Insup::Tracker::GitTracker < Insup::Tracker
5
-
6
5
  tracker :git
7
6
 
8
- def initialize config = nil
7
+ def initialize(base, config)
9
8
  super
10
9
  @git = ::Insup::Git.new(@path)
11
10
  end
@@ -2,18 +2,15 @@ require 'base64'
2
2
  require_relative '../insales'
3
3
 
4
4
  class Insup::Uploader::InsalesUploader < Insup::Uploader
5
-
6
5
  uploader :insales
7
6
 
8
- InsalesUploaderError = Class.new(Insup::Exceptions::UploaderError)
9
-
10
7
  def initialize(settings)
11
8
  super
12
9
  @insales = Insup::Insales.new(settings)
13
10
  @insales.configure_api
14
11
 
15
12
  if !theme
16
- raise Insup::Exceptions::UploaderError, "Theme #{theme_id} is not found in the Insales shop"
13
+ fail Insup::Exceptions::FatalUploaderError, "Theme #{theme_id} is not found in the Insales shop"
17
14
  end
18
15
 
19
16
  assets_list(true)
@@ -40,10 +37,13 @@ class Insup::Uploader::InsalesUploader < Insup::Uploader
40
37
 
41
38
  changed
42
39
  notify_observers(CREATING_FILE, file)
43
- asset_type = get_asset_type(file.path)
40
+ asset_type = ::Insup::Insales::Asset.get_type(file.path)
44
41
 
45
42
  if !asset_type
46
- raise InsalesUploaderError, "Cannot determine asset type for file #{file.path}"
43
+ msg = "Cannot determine asset type for file #{file.path}"
44
+ changed
45
+ notify_observers(ERROR, file, msg)
46
+ raise Insup::Exceptions::RecoverableUploaderError, msg
47
47
  end
48
48
 
49
49
  file_contents = File.read(file.path)
@@ -60,10 +60,16 @@ class Insup::Uploader::InsalesUploader < Insup::Uploader
60
60
  hash[:attachment] = Base64.encode64(file_contents)
61
61
  end
62
62
 
63
- asset = ::Insup::Insales::Asset.new(hash)
64
- assets_list << asset
65
- changed
66
- notify_observers(CREATED_FILE, file)
63
+ begin
64
+ asset = ::Insup::Insales::Asset.create(hash)
65
+ assets_list << asset
66
+ changed
67
+ notify_observers(CREATED_FILE, file)
68
+ rescue ActiveResource::ServerError => ex
69
+ changed
70
+ notify_observers(ERROR, file, ex.message)
71
+ raise Insup::Exceptions::RecoverableUploaderError, "Server error occured when creating file #{file.path}"
72
+ end
67
73
  end
68
74
 
69
75
  def upload_modified_file(file)
@@ -76,48 +82,57 @@ class Insup::Uploader::InsalesUploader < Insup::Uploader
76
82
 
77
83
  changed
78
84
  notify_observers(MODIFYING_FILE, file)
79
-
80
85
  file_contents = File.read(file.path)
81
86
 
82
87
  if asset.content_type.start_with? 'text/'
83
- res = asset.update_attribute(:content, file_contents)
84
- if !res
85
- process_error(asset, file)
88
+ begin
89
+ res = asset.update_attribute(:content, file_contents)
90
+
91
+ if !res
92
+ process_error(asset, file)
93
+ return
94
+ end
95
+
96
+ changed
97
+ notify_observers(MODIFIED_FILE, file)
98
+ rescue ActiveResource::ServerError => ex
99
+ changed
100
+ notify_observers(ERROR, file, ex.message)
101
+ raise Insup::Exceptions::RecoverableUploaderError, "Server error occured when updating file #{file.path}"
86
102
  end
87
103
  else
88
104
  remove_file(file)
89
105
  upload_new_file(file)
90
106
  end
91
-
92
- changed
93
- notify_observers(MODIFIED_FILE, file)
94
107
  end
95
108
 
96
109
  def remove_file(file)
97
110
  asset = find_asset(file)
98
-
111
+
99
112
  if !asset
100
- raise InsalesUploaderError, "Cannot find remote counterpart for file #{file.path}"
113
+ msg = "Cannot find remote counterpart for file #{file.path}"
114
+ changed
115
+ notify_observers(ERROR, file, msg)
116
+ raise Insup::Exceptions::RecoverableUploaderError, "Cannot find remote counterpart for file #{file.path}"
101
117
  end
102
118
 
103
119
  changed
104
120
  notify_observers(DELETING_FILE, file)
105
121
 
106
- if pd=asset.destroy
107
- assets_list.delete(asset)
122
+ begin
123
+ if asset.destroy
124
+ assets_list.delete(asset)
125
+ changed
126
+ notify_observers(DELETED_FILE, file)
127
+ end
128
+ rescue ActiveResource::ServerError => ex
129
+ changed
130
+ notify_observers(ERROR, file, ex.message)
131
+ raise Insup::Exceptions::RecoverableUploaderError, "Server error occured when deleting file #{file.path}"
108
132
  end
109
-
110
- changed
111
- notify_observers(DELETED_FILE, file)
112
133
  end
113
134
 
114
135
  private
115
- ASSET_TYPE_MAP = {
116
- 'media/' => 'Asset::Media',
117
- 'snippets/' => 'Asset::Snippet',
118
- 'templates/' => 'Asset::Template'
119
- }.freeze
120
-
121
136
  def process_error(entity, file)
122
137
  changed
123
138
  entity.errors.full_messages.each do |err|
@@ -126,19 +141,6 @@ private
126
141
  end
127
142
  end
128
143
 
129
- def get_asset_type path
130
- res = nil
131
-
132
- ASSET_TYPE_MAP.each do |k,v|
133
- if path.start_with? k
134
- res = v
135
- break
136
- end
137
- end
138
-
139
- res
140
- end
141
-
142
144
  def theme
143
145
  @theme ||= themes[theme_id]
144
146
  end
@@ -151,15 +153,18 @@ private
151
153
  @themes ||= Hash[@insales.themes.map{|t| [t.id, t]}]
152
154
  end
153
155
 
154
- def find_asset file
155
- asset_type = get_asset_type(file.path)
156
-
157
- if(!asset_type)
158
- raise InsalesUploaderError, "Cannot determine asset type for file #{file.path}"
156
+ def find_asset(file)
157
+ asset_type = ::Insup::Insales::Asset.get_type(file.path)
158
+
159
+ if !asset_type
160
+ msg = "Cannot determine asset type for file #{file.path}"
161
+ changed
162
+ notify_observers(ERROR, file, msg)
163
+ raise Insup::Exceptions::RecoverableUploaderError, "Cannot determine asset type for file #{file.path}"
159
164
  end
160
165
 
161
- files = assets_list.select do |el|
162
- el.type == asset_type && (el.human_readable_name == file.file_name || el.name == file.file_name)
166
+ files = assets_list.select do |el|
167
+ el.type == asset_type && el.filename == file.file_name
163
168
  end
164
169
 
165
170
  if files && !files.empty?
@@ -1,3 +1,3 @@
1
1
  class Insup
2
- VERSION = '0.2'
2
+ VERSION = '0.3'
3
3
  end
@@ -1,9 +1,9 @@
1
1
  require_relative '../../../spec_helper'
2
2
 
3
- describe 'Insup::Console::UploadObserver' do
3
+ describe Insup::Console::UploadObserver do
4
4
 
5
5
  it 'should handle all types of events' do
6
- @observer = Insup::Console::UploadObserver.new
6
+ @observer = described_class.new
7
7
 
8
8
  [Insup::Uploader::CREATING_FILE,
9
9
  Insup::Uploader::CREATED_FILE,
@@ -12,7 +12,9 @@ describe 'Insup::Console::UploadObserver' do
12
12
  Insup::Uploader::DELETING_FILE,
13
13
  Insup::Uploader::DELETED_FILE,
14
14
  Insup::Uploader::BATCH_UPLOADING_FILES,
15
- Insup::Uploader::BATCH_UPLOADED_FILES].each do |event|
15
+ Insup::Uploader::BATCH_UPLOADED_FILES,
16
+ Insup::Uploader::ERROR
17
+ ].each do |event|
16
18
  expect {@observer.update(event, Insup::TrackedFile.new('path/to.file'))}.not_to raise_error
17
19
  end
18
20
  end
@@ -1,7 +1,7 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
- describe 'Insup::Git' do
3
+ describe Insup::Git do
4
4
  it 'should get status' do
5
- expect{git = Insup::Git.new(Dir.getwd)}.not_to raise_error
5
+ expect{git = described_class.new(Dir.getwd)}.not_to raise_error
6
6
  end
7
7
  end
@@ -1,8 +1,8 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
- describe 'Insup::Settings' do
3
+ describe Insup::Settings do
4
4
  before(:each) do
5
- @settings = Insup::Settings.new('spec/support/.insup')
5
+ @settings = described_class.new('spec/support/.insup')
6
6
  end
7
7
 
8
8
  it 'should have correct tracked locations' do
@@ -1,9 +1,9 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
- describe 'Insup::Tracker' do
3
+ describe Insup::Tracker do
4
4
 
5
5
  before(:each) do
6
- @tracker = Insup::Tracker.new()
6
+ @tracker = described_class.new()
7
7
  end
8
8
 
9
9
  end
@@ -1,5 +1,5 @@
1
1
  require_relative '../../../spec_helper'
2
2
 
3
- describe 'Insup::Uploader::InsalesUploader' do
3
+ describe Insup::Uploader::InsalesUploader do
4
4
 
5
5
  end
@@ -1,5 +1,5 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
- describe 'Insup' do
3
+ describe Insup do
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insup
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - HttpLab
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-03 00:00:00.000000000 Z
12
+ date: 2014-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '2.10'
34
+ version: '2.11'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '2.10'
41
+ version: '2.11'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: listen
44
44
  requirement: !ruby/object:Gem::Requirement