esp-commons 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/models/esp_commons/image.rb +69 -0
 - data/lib/esp-commons/engine.rb +17 -1
 - data/lib/esp-commons/version.rb +1 -1
 - metadata +26 -15
 - data/config/initializers/errbit.rb +0 -11
 
| 
         @@ -0,0 +1,69 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class EspCommons::Image < APISmith::Smash
         
     | 
| 
      
 2 
     | 
    
         
            +
              property :url
         
     | 
| 
      
 3 
     | 
    
         
            +
              property :description
         
     | 
| 
      
 4 
     | 
    
         
            +
              property :thumbnail
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              property :id,         :transformer => :to_i
         
     | 
| 
      
 7 
     | 
    
         
            +
              property :width,      :transformer => :to_i
         
     | 
| 
      
 8 
     | 
    
         
            +
              property :height,     :transformer => :to_i
         
     | 
| 
      
 9 
     | 
    
         
            +
              property :filename
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              attr_writer :aspect_ratio
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              def parse_url
         
     | 
| 
      
 15 
     | 
    
         
            +
                self.tap do | image |
         
     | 
| 
      
 16 
     | 
    
         
            +
                  image.id, image.width, image.height, image.filename = url.match(%r{files/(\d+)/(\d+)-(\d+)/(.*)})[1..-1]
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              def build_url
         
     | 
| 
      
 21 
     | 
    
         
            +
                self.tap do | image |
         
     | 
| 
      
 22 
     | 
    
         
            +
                  image.url = "#{Settings['vfs.url']}/files/#{image.id}/#{image.width}-#{image.height}/#{image.filename}"
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              def image?
         
     | 
| 
      
 27 
     | 
    
         
            +
                width && height
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              def aspect_ratio
         
     | 
| 
      
 31 
     | 
    
         
            +
                @aspect_ratio ||= width.to_f / height
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              def resize(aspect_ratio)
         
     | 
| 
      
 35 
     | 
    
         
            +
                self.aspect_ratio = aspect_ratio
         
     | 
| 
      
 36 
     | 
    
         
            +
                if width && !height
         
     | 
| 
      
 37 
     | 
    
         
            +
                  self.height = new_height
         
     | 
| 
      
 38 
     | 
    
         
            +
                elsif !width && height
         
     | 
| 
      
 39 
     | 
    
         
            +
                  self.width = new_width
         
     | 
| 
      
 40 
     | 
    
         
            +
                else
         
     | 
| 
      
 41 
     | 
    
         
            +
                  self.width = self.height = 100 if !width && !height
         
     | 
| 
      
 42 
     | 
    
         
            +
                  if height >= new_height
         
     | 
| 
      
 43 
     | 
    
         
            +
                    self.height = new_height
         
     | 
| 
      
 44 
     | 
    
         
            +
                  else
         
     | 
| 
      
 45 
     | 
    
         
            +
                    self.width = new_width
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
                self
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              def new_height
         
     | 
| 
      
 52 
     | 
    
         
            +
                @new_height ||= width / aspect_ratio
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
              def new_width
         
     | 
| 
      
 56 
     | 
    
         
            +
                @new_width ||= height * aspect_ratio
         
     | 
| 
      
 57 
     | 
    
         
            +
              end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
              def create_thumbnail(options)
         
     | 
| 
      
 60 
     | 
    
         
            +
                return unless image?
         
     | 
| 
      
 61 
     | 
    
         
            +
                self.thumbnail = EspCommons::Image.new(options.merge(:id => id, :filename => filename, :description => description))
         
     | 
| 
      
 62 
     | 
    
         
            +
                                                  .resize(aspect_ratio)
         
     | 
| 
      
 63 
     | 
    
         
            +
                                                  .build_url
         
     | 
| 
      
 64 
     | 
    
         
            +
              end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
              def as_json(options={})
         
     | 
| 
      
 67 
     | 
    
         
            +
                super(options.merge(:only => %w[url width height thumbnail description]))
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/esp-commons/engine.rb
    CHANGED
    
    | 
         @@ -1,9 +1,12 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'airbrake'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'configliere'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'api_smith'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       1 
5 
     | 
    
         
             
            module EspCommons
         
     | 
| 
       2 
6 
     | 
    
         
             
              class Engine < ::Rails::Engine
         
     | 
| 
       3 
7 
     | 
    
         
             
                isolate_namespace EspCommons
         
     | 
| 
       4 
8 
     | 
    
         | 
| 
       5 
9 
     | 
    
         
             
                config.before_configuration do
         
     | 
| 
       6 
     | 
    
         
            -
                  require 'configliere'
         
     | 
| 
       7 
10 
     | 
    
         
             
                  Settings.read(Rails.root.join('config', 'settings.yml')) if Rails.root.join('config', 'settings.yml').exist?
         
     | 
| 
       8 
11 
     | 
    
         
             
                  Settings.defaults Settings.extract!(Rails.env)[Rails.env] || {}
         
     | 
| 
       9 
12 
     | 
    
         
             
                  Settings.extract!(:test, :development, :production)
         
     | 
| 
         @@ -29,6 +32,19 @@ module EspCommons 
     | 
|
| 
       29 
32 
     | 
    
         
             
                  end
         
     | 
| 
       30 
33 
     | 
    
         
             
                end
         
     | 
| 
       31 
34 
     | 
    
         | 
| 
      
 35 
     | 
    
         
            +
                config.before_initialize do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  if Settings['errors.key'].present?
         
     | 
| 
      
 37 
     | 
    
         
            +
                    Airbrake.configure do |config|
         
     | 
| 
      
 38 
     | 
    
         
            +
                      config.api_key = Settings['errors.key']
         
     | 
| 
      
 39 
     | 
    
         
            +
                      URI.parse(Settings['errors.url']).tap do | url |
         
     | 
| 
      
 40 
     | 
    
         
            +
                        config.host = url.host
         
     | 
| 
      
 41 
     | 
    
         
            +
                        config.port = url.port
         
     | 
| 
      
 42 
     | 
    
         
            +
                        config.secure = url.scheme.inquiry.https?
         
     | 
| 
      
 43 
     | 
    
         
            +
                      end
         
     | 
| 
      
 44 
     | 
    
         
            +
                    end
         
     | 
| 
      
 45 
     | 
    
         
            +
                  end
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       32 
48 
     | 
    
         
             
                config.after_initialize do
         
     | 
| 
       33 
49 
     | 
    
         
             
                  Rails.logger.level = ActiveSupport::BufferedLogger::Severity::WARN if Rails.env.production?
         
     | 
| 
       34 
50 
     | 
    
         
             
                end
         
     | 
    
        data/lib/esp-commons/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: esp-commons
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,11 +9,11 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2012-02 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-03-02 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: airbrake
         
     | 
| 
       16 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: &8290800 !ruby/object:Gem::Requirement
         
     | 
| 
       17 
17 
     | 
    
         
             
                none: false
         
     | 
| 
       18 
18 
     | 
    
         
             
                requirements:
         
     | 
| 
       19 
19 
     | 
    
         
             
                - - ! '>='
         
     | 
| 
         @@ -21,10 +21,10 @@ dependencies: 
     | 
|
| 
       21 
21 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       22 
22 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       23 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       24 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: *8290800
         
     | 
| 
       25 
25 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       26 
26 
     | 
    
         
             
              name: configliere
         
     | 
| 
       27 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 27 
     | 
    
         
            +
              requirement: &8290040 !ruby/object:Gem::Requirement
         
     | 
| 
       28 
28 
     | 
    
         
             
                none: false
         
     | 
| 
       29 
29 
     | 
    
         
             
                requirements:
         
     | 
| 
       30 
30 
     | 
    
         
             
                - - ! '>='
         
     | 
| 
         @@ -32,10 +32,10 @@ dependencies: 
     | 
|
| 
       32 
32 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       33 
33 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       34 
34 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       35 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 35 
     | 
    
         
            +
              version_requirements: *8290040
         
     | 
| 
       36 
36 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       37 
37 
     | 
    
         
             
              name: rails
         
     | 
| 
       38 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 38 
     | 
    
         
            +
              requirement: &8288860 !ruby/object:Gem::Requirement
         
     | 
| 
       39 
39 
     | 
    
         
             
                none: false
         
     | 
| 
       40 
40 
     | 
    
         
             
                requirements:
         
     | 
| 
       41 
41 
     | 
    
         
             
                - - ! '>='
         
     | 
| 
         @@ -43,10 +43,21 @@ dependencies: 
     | 
|
| 
       43 
43 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       44 
44 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       45 
45 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       46 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 46 
     | 
    
         
            +
              version_requirements: *8288860
         
     | 
| 
      
 47 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 48 
     | 
    
         
            +
              name: api_smith
         
     | 
| 
      
 49 
     | 
    
         
            +
              requirement: &8303180 !ruby/object:Gem::Requirement
         
     | 
| 
      
 50 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 51 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 52 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 53 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 54 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 55 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 56 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 57 
     | 
    
         
            +
              version_requirements: *8303180
         
     | 
| 
       47 
58 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       48 
59 
     | 
    
         
             
              name: unicorn
         
     | 
| 
       49 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 60 
     | 
    
         
            +
              requirement: &8301560 !ruby/object:Gem::Requirement
         
     | 
| 
       50 
61 
     | 
    
         
             
                none: false
         
     | 
| 
       51 
62 
     | 
    
         
             
                requirements:
         
     | 
| 
       52 
63 
     | 
    
         
             
                - - ! '>='
         
     | 
| 
         @@ -54,10 +65,10 @@ dependencies: 
     | 
|
| 
       54 
65 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       55 
66 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       56 
67 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       57 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 68 
     | 
    
         
            +
              version_requirements: *8301560
         
     | 
| 
       58 
69 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       59 
70 
     | 
    
         
             
              name: sqlite3
         
     | 
| 
       60 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 71 
     | 
    
         
            +
              requirement: &8300080 !ruby/object:Gem::Requirement
         
     | 
| 
       61 
72 
     | 
    
         
             
                none: false
         
     | 
| 
       62 
73 
     | 
    
         
             
                requirements:
         
     | 
| 
       63 
74 
     | 
    
         
             
                - - ! '>='
         
     | 
| 
         @@ -65,7 +76,7 @@ dependencies: 
     | 
|
| 
       65 
76 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       66 
77 
     | 
    
         
             
              type: :development
         
     | 
| 
       67 
78 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       68 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 79 
     | 
    
         
            +
              version_requirements: *8300080
         
     | 
| 
       69 
80 
     | 
    
         
             
            description: Description of EspCommons.
         
     | 
| 
       70 
81 
     | 
    
         
             
            email:
         
     | 
| 
       71 
82 
     | 
    
         
             
            - mail@openteam.ru
         
     | 
| 
         @@ -73,7 +84,7 @@ executables: [] 
     | 
|
| 
       73 
84 
     | 
    
         
             
            extensions: []
         
     | 
| 
       74 
85 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       75 
86 
     | 
    
         
             
            files:
         
     | 
| 
       76 
     | 
    
         
            -
            -  
     | 
| 
      
 87 
     | 
    
         
            +
            - app/models/esp_commons/image.rb
         
     | 
| 
       77 
88 
     | 
    
         
             
            - config/initializers/sunspot.rb
         
     | 
| 
       78 
89 
     | 
    
         
             
            - config/locales/datetime.ru.yml
         
     | 
| 
       79 
90 
     | 
    
         
             
            - config/locales/commons.ru.yml
         
     | 
| 
         @@ -101,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       101 
112 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       102 
113 
     | 
    
         
             
                  segments:
         
     | 
| 
       103 
114 
     | 
    
         
             
                  - 0
         
     | 
| 
       104 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 115 
     | 
    
         
            +
                  hash: -2181019276315037716
         
     | 
| 
       105 
116 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       106 
117 
     | 
    
         
             
              none: false
         
     | 
| 
       107 
118 
     | 
    
         
             
              requirements:
         
     | 
| 
         @@ -110,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       110 
121 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       111 
122 
     | 
    
         
             
                  segments:
         
     | 
| 
       112 
123 
     | 
    
         
             
                  - 0
         
     | 
| 
       113 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 124 
     | 
    
         
            +
                  hash: -2181019276315037716
         
     | 
| 
       114 
125 
     | 
    
         
             
            requirements: []
         
     | 
| 
       115 
126 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       116 
127 
     | 
    
         
             
            rubygems_version: 1.8.15
         
     | 
| 
         @@ -1,11 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            if Settings['errors.key'].present?
         
     | 
| 
       2 
     | 
    
         
            -
              require 'airbrake'
         
     | 
| 
       3 
     | 
    
         
            -
              Airbrake.configure do |config|
         
     | 
| 
       4 
     | 
    
         
            -
                config.api_key = Settings['errors.key']
         
     | 
| 
       5 
     | 
    
         
            -
                URI.parse(Settings['errors.url']).tap do | url |
         
     | 
| 
       6 
     | 
    
         
            -
                  config.host = url.host
         
     | 
| 
       7 
     | 
    
         
            -
                  config.port = url.port
         
     | 
| 
       8 
     | 
    
         
            -
                  config.secure = url.scheme.inquiry.https?
         
     | 
| 
       9 
     | 
    
         
            -
                end
         
     | 
| 
       10 
     | 
    
         
            -
              end
         
     | 
| 
       11 
     | 
    
         
            -
            end
         
     |