brocade 1.0.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Andy Stewart
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Brocade
2
+
3
+ Brocade generates barcodes for Rails ActiveRecord models.
4
+
5
+ I extracted this from one of my projects and, although the code is nice and extensible, right now it only does what I need in that project. So for example it could produce barcodes in any symbology -- but currently only does Code 128.
6
+
7
+ There are two parts to Brocade: barcode generation and file management (because the barcodes are saved as image files). I use [Barby][barby] to generate the barcodes and code copied from [Paperclip][paperclip] to manage the files.
8
+
9
+
10
+ ## Features
11
+
12
+ * No configuration necessary...or possible ;)
13
+ * Supports Code 128 symbology. Could support any symbology.
14
+ * Generates barcode images as PNGs via ImageMagick. Could support other output formats.
15
+ * Stores barcode images on disk. Could support other storage.
16
+
17
+
18
+ ## Basic Usage
19
+
20
+ Brocade is simple to use:
21
+
22
+ class Item < ActiveRecord::Base
23
+ has_barcode
24
+
25
+ def barcodable
26
+ :serial_number
27
+ end
28
+ end
29
+
30
+ First declare declare your model `has_barcode`. Second override the `barcodable` method to return the name of the method Brocade should call to get the data to barcode.
31
+
32
+ Now you get this:
33
+
34
+ >> item = Item.create :serial_number => 42, :name => 'Deep Thought'
35
+ # writes barcode to /path/to/your/app/public/system/barcodes/items/3615/code128.png
36
+
37
+ -- assuming `item`'s id is 3615.
38
+
39
+ >> item.update_attributes :name => 'Deeper Thought'
40
+ # no change to barcode
41
+
42
+ >> item.update_attributes :serial_number => 153
43
+ # writes barcode to /path/to/your/app/public/system/barcodes/items/3615/code128.png
44
+ # i.e. writes out a new barcode image over the top of the original one
45
+
46
+ >> item.barcode_path
47
+ # => "/path/to/your/app/public/system/barcodes/items/3615/code128.png"
48
+
49
+ >> item.barcode_url
50
+ # => "/system/barcodes/items/3615/code128.png"
51
+
52
+ >> item.destroy
53
+ # deletes barcode image.
54
+
55
+
56
+ ## Installation.
57
+
58
+ Install as a gem. In your `config.rb`:
59
+
60
+ config.gem 'brocade'
61
+
62
+
63
+ ## Dependencies
64
+
65
+ The [Barby][barby] and [PNG][png] gems, and ImageMagick.
66
+
67
+
68
+ ## Problems
69
+
70
+ Please use GitHub's [issue tracker](http://github.com/airblade/brocade/issues).
71
+
72
+
73
+ ## To do
74
+
75
+ * Tests. Yes, yes, I know.
76
+ * Configurable way to specify data to be barcoded.
77
+ * Configurable symbology.
78
+ * Multiple symbologies per model.
79
+ * Configurable file path and URL.
80
+ * Other outputters.
81
+ * Other storage.
82
+
83
+
84
+ ## Further reading
85
+
86
+ * [Barcode Basics](http://www.barcodediscount.com/solutions/library/barcode_basics.htm)
87
+ * [Barcode Online Reference](http://www.teklynx.com/barcodes/article_1.html)
88
+
89
+
90
+ ## Inspiration
91
+
92
+ * [Barby][barby]
93
+ * [Paperclip][paperclip]
94
+
95
+
96
+ ## Intellectual Property
97
+
98
+ Copyright (c) 2010 Andy Stewart. See LICENSE for details.
99
+
100
+
101
+ [barby]: http://github.com/toretore/barby
102
+ [paperclip]: http://github.com/thoughtbot/paperclip
103
+ [png]: http://seattlerb.rubyforge.org/png/
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "brocade"
8
+ gem.summary = %Q{Generates barcodes for Rails ActiveRecord models.}
9
+ gem.email = "boss@airbladesoftware.com"
10
+ gem.homepage = "http://github.com/airblade/brocade"
11
+ gem.authors = ["Andy Stewart"]
12
+ gem.add_dependency 'barby'
13
+ gem.add_dependency 'png'
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "brocade #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'brocade'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ puts 'Thank you for installing Brocade. You can visit http://github.com/airblade/brocade to read the documentation.'
@@ -0,0 +1,87 @@
1
+ require 'barby'
2
+ require 'barby/outputter/png_outputter'
3
+
4
+ # A way of managing barcodes based closely on Thoughtbot's Paperclip.
5
+ # It consists of two parts: barcode creation and file management.
6
+ # Currently the file management is DIY but it might be better to delegate to Paperclip.
7
+ module Brocade
8
+
9
+ def self.included(base)
10
+ base.send :extend, ClassMethods
11
+ end
12
+
13
+ module ClassMethods
14
+ def has_barcode
15
+ send :include, InstanceMethods
16
+
17
+ after_create :create_barcode
18
+ before_update :update_barcode
19
+ after_destroy :destroy_barcode
20
+ end
21
+ end
22
+
23
+ module InstanceMethods
24
+ # Returns the name of the method (as a symbol) to call to get the
25
+ # data to be barcoded.
26
+ #
27
+ # Override this in your model as appropriate.
28
+ def barcodable
29
+ :code
30
+ end
31
+
32
+ def symbology
33
+ :code128
34
+ end
35
+
36
+ def create_barcode
37
+ barcode = Barby::Code128B.new send(barcodable)
38
+ path = barcode_path
39
+ FileUtils.mkdir_p File.dirname(path)
40
+ File.open(path, 'wb') do |f|
41
+ f.write barcode.to_png
42
+ end
43
+ FileUtils.chmod 0644, path
44
+ end
45
+
46
+ def update_barcode
47
+ create_barcode if changed.include? barcodable
48
+ end
49
+
50
+ def destroy_barcode
51
+ path = barcode_path
52
+ begin
53
+ FileUtils.rm path if File.exist? path
54
+ rescue Errno::ENOENT => e
55
+ # Ignore file-not-found; let everything else pass.
56
+ end
57
+ begin
58
+ while true
59
+ path = File.dirname path
60
+ FileUtils.rmdir path
61
+ end
62
+ rescue Errno::EEXIST, Errno::ENOTEMPTY, Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR
63
+ # Stop trying to remove parent directories
64
+ rescue SystemCallError => e
65
+ #log("There was an unexpected error while deleting directories: #{e.class}")
66
+ # Ignore it
67
+ end
68
+ end
69
+
70
+ def barcode_url
71
+ "/system/barcodes/#{klass}/#{id}/#{symbology}.png"
72
+ end
73
+
74
+ def barcode_path
75
+ "#{RAILS_ROOT}/public/system/barcodes/#{klass}/#{id}/#{symbology}.png"
76
+ end
77
+
78
+ def klass
79
+ self.class.to_s.underscore.pluralize
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ if Object.const_defined? 'ActiveRecord'
86
+ ActiveRecord::Base.send :include, Brocade
87
+ end
data/lib/brocade.rb ADDED
@@ -0,0 +1 @@
1
+ require 'brocade/has_barcode'
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'brocade'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestBrocade < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brocade
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andy Stewart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-10 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: barby
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: png
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: thoughtbot-shoulda
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description:
46
+ email: boss@airbladesoftware.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.md
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - VERSION
61
+ - init.rb
62
+ - install.rb
63
+ - lib/brocade.rb
64
+ - lib/brocade/has_barcode.rb
65
+ - test/helper.rb
66
+ - test/test_brocade.rb
67
+ has_rdoc: true
68
+ homepage: http://github.com/airblade/brocade
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.5
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Generates barcodes for Rails ActiveRecord models.
95
+ test_files:
96
+ - test/helper.rb
97
+ - test/test_brocade.rb