has_barcode 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,17 @@
1
- *.sw?
2
- .DS_Store
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
3
9
  coverage
4
- rdoc
10
+ doc/
11
+ lib/bundler/man
5
12
  pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use default@has_barcode --create
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in has_barcode.gemspec
4
+ gemspec
data/README.rdoc CHANGED
@@ -1,24 +1,49 @@
1
1
  = has_barcode
2
2
 
3
- A nice wrapper for Barcode generation using barby
3
+ {<img src="https://secure.travis-ci.org/dpickett/has_barcode.png" />}[http://travis-ci.org/dpickett/has_barcode]
4
4
 
5
- class SomethingImportant
6
- has_barcode :barcode,
7
- :outputter => :png,
5
+ A nice wrapper for Barcode generation using {barby}[https://github.com/toretore/barby].
6
+
7
+ class Product
8
+ include HasBarcode
9
+
10
+ has_barcode :barcode,
11
+ :outputter => :png,
8
12
  :type => :code_39,
9
- :value => Proc.new{|p| p.number}
13
+ :value => Proc.new { |p| p.number }
10
14
 
11
15
  def number
12
16
  self.id
13
17
  end
14
18
  end
15
19
 
16
- SomethingImportant.new.barcode => Barby::Code39 object
17
- SomethingImportant.new.barcode_data => <Barby::Code39 object>.to_png
20
+ Product.new.barcode # => Barby::Code39 object
21
+ Product.new.barcode_data # => <Barby::Code39 object>.to_png
22
+
23
+ == Why has_barcode is a good choice for Heroku
24
+ Other libraries – such as {barcode_generator}[https://github.com/anujluthra/barcode-generator] – commonly rely on {gbarcode}[https://github.com/ahx/gbarcode], a GNU Barcode C library. This is problem since you need to install GNU barcode which {Heroku does not support}[https://github.com/perezd/barcoder/issues/1]. Luckily <tt>has_barcode</tt> doesn't have this dependency.
25
+
26
+ A typical Heroku setup might look like:
27
+
28
+ class Coupon < ActiveRecord::Base
29
+ include HasBarcode
30
+
31
+ has_barcode :barcode,
32
+ :outputter => :svg,
33
+ :type => :code_39,
34
+ :value => Proc.new { |c| c.id }
35
+
36
+ end
37
+
38
+ Notice we're using the <tt>svg</tt> outputter. This is good choice since it doesn't need to store images in the file system, which can be an issue given {Heroku's read only file system}[http://devcenter.heroku.com/articles/read-only-filesystem].
39
+
40
+ To display your barcode in the view, do something like:
41
+
42
+ @coupon.barcode_data.html_safe
18
43
 
19
44
 
20
45
  == Note on Patches/Pull Requests
21
-
46
+
22
47
  * Fork the project.
23
48
  * Make your feature addition or bug fix.
24
49
  * Add tests for it. This is important so I don't break it in a
data/Rakefile CHANGED
@@ -1,47 +1,15 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
3
 
4
4
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "has_barcode"
8
- gem.summary = %Q{Nice class method wrapper for Barby}
9
- gem.description = %Q{Nice class method wrapper for Barby}
10
- gem.email = "dpickett@enlightsolutions.com"
11
- gem.homepage = "http://github.com/dpickett/has_barcode"
12
- gem.authors = ["Dan Pickett"]
13
- gem.add_dependency "activesupport"
14
- gem.add_dependency "barby"
15
- gem.add_development_dependency "rspec"
16
- gem.add_development_dependency "yard"
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- Jeweler::GemcutterTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
- end
23
-
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
34
- end
5
+ require 'rspec/core/rake_task'
35
6
 
36
- task :spec => :check_dependencies
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new do |t|
9
+ end
37
10
 
38
- task :default => :spec
11
+ task :default => :spec
39
12
 
40
- begin
41
- require 'yard'
42
- YARD::Rake::YardocTask.new
43
13
  rescue LoadError
44
- task :yardoc do
45
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
46
- end
47
- end
14
+ puts "RSpec is not installed"
15
+ end
data/has_barcode.gemspec CHANGED
@@ -1,67 +1,26 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/has_barcode/version', __FILE__)
5
3
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{has_barcode}
8
- s.version = "0.1.1"
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dan Pickett"]
6
+ gem.email = ["dpickett@enlightsolutions.com"]
7
+ gem.description = %q{Nice class method wrapper for Barby}
8
+ gem.summary = %q{Nice class method wrapper for Barby}
9
+ gem.homepage = ""
9
10
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Dan Pickett"]
12
- s.date = %q{2009-10-05}
13
- s.description = %q{Nice class method wrapper for Barby}
14
- s.email = %q{dpickett@enlightsolutions.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "has_barcode.gemspec",
27
- "lib/has_barcode.rb",
28
- "lib/has_barcode/configuration.rb",
29
- "spec/has_barcode/configuration_spec.rb",
30
- "spec/has_barcode_spec.rb",
31
- "spec/models/has_png_barcode.rb",
32
- "spec/spec_helper.rb"
33
- ]
34
- s.homepage = %q{http://github.com/dpickett/has_barcode}
35
- s.rdoc_options = ["--charset=UTF-8"]
36
- s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.5}
38
- s.summary = %q{Nice class method wrapper for Barby}
39
- s.test_files = [
40
- "spec/has_barcode/configuration_spec.rb",
41
- "spec/has_barcode_spec.rb",
42
- "spec/models/has_png_barcode.rb",
43
- "spec/spec_helper.rb"
44
- ]
45
-
46
- if s.respond_to? :specification_version then
47
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
- s.specification_version = 3
49
-
50
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
52
- s.add_runtime_dependency(%q<barby>, [">= 0"])
53
- s.add_development_dependency(%q<rspec>, [">= 0"])
54
- s.add_development_dependency(%q<yard>, [">= 0"])
55
- else
56
- s.add_dependency(%q<activesupport>, [">= 0"])
57
- s.add_dependency(%q<barby>, [">= 0"])
58
- s.add_dependency(%q<rspec>, [">= 0"])
59
- s.add_dependency(%q<yard>, [">= 0"])
60
- end
61
- else
62
- s.add_dependency(%q<activesupport>, [">= 0"])
63
- s.add_dependency(%q<barby>, [">= 0"])
64
- s.add_dependency(%q<rspec>, [">= 0"])
65
- s.add_dependency(%q<yard>, [">= 0"])
66
- end
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "has_barcode"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = HasBarcode::VERSION
17
+
18
+ gem.add_dependency("activesupport", [">= 3"])
19
+ gem.add_dependency("i18n")
20
+ gem.add_dependency("barby", [">= 0"])
21
+ gem.add_dependency("rake")
22
+
23
+ gem.add_development_dependency("rspec", [">= 0"])
24
+ gem.add_development_dependency("chunky_png", [">= 0"])
25
+ gem.add_development_dependency("yard", [">= 0"])
67
26
  end
@@ -2,16 +2,17 @@ module HasBarcode
2
2
  class Configuration
3
3
  attr_reader :name, :barcode_class, :outputter_class
4
4
  def initialize(*args)
5
- opts = args.extract_options!
6
- opts.symbolize_keys!
5
+ opts = ActiveSupport::HashWithIndifferentAccess.new(args.last.kind_of?(Hash) ? (args.last || {}) : {})
7
6
 
8
7
  @name = args.first
9
- @barcode_class = Barby.const_get("#{opts[:type].to_s.classify}")
8
+
9
+ require "barby/barcode/#{opts[:type]}"
10
+ @barcode_class = Barby.const_get(ActiveSupport::Inflector.classify("#{opts[:type].to_s}"))
10
11
 
11
12
  require "barby/outputter/#{opts[:outputter]}_outputter"
12
- @outputter = Barby.const_get("#{opts[:outputter]}_outputter".classify)
13
+ @outputter = Barby.const_get(ActiveSupport::Inflector.classify("#{opts[:outputter]}_outputter"))
13
14
  end
14
15
 
15
-
16
+
16
17
  end
17
18
  end
@@ -0,0 +1,3 @@
1
+ module HasBarcode
2
+ VERSION = "0.2.0"
3
+ end
data/lib/has_barcode.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require "rubygems"
2
+ require "i18n"
2
3
  require "active_support"
4
+ require "active_support/hash_with_indifferent_access.rb"
5
+ require "active_support/inflector.rb"
3
6
  require "barby"
4
7
 
5
8
  require "has_barcode/configuration"
@@ -16,7 +19,11 @@ module HasBarcode
16
19
  @@barcode_configurations[args.first] = HasBarcode::Configuration.new(options)
17
20
 
18
21
  define_method args.first do
19
- @@barcode_configurations[args.first].barcode_class.new(options[:value].call(self))
22
+ if options[:type] == :code_128
23
+ @@barcode_configurations[args.first].barcode_class.new(options[:value].call(self), 'A')
24
+ else
25
+ @@barcode_configurations[args.first].barcode_class.new(options[:value].call(self))
26
+ end
20
27
  end
21
28
 
22
29
  define_method "#{args.first}_data" do
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,5 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
1
  require 'has_barcode'
4
- require 'spec'
5
- require 'spec/autorun'
6
2
 
7
- require 'spec/models/has_png_barcode'
3
+ require 'rspec'
8
4
 
9
- Spec::Runner.configure do |config|
10
-
11
- end
5
+ require "#{File.dirname(__FILE__)}/models/has_png_barcode"
metadata CHANGED
@@ -1,110 +1,150 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: has_barcode
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Dan Pickett
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-10-05 00:00:00 -04:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-03 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: activesupport
16
+ requirement: &2152242240 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
17
22
  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
23
+ prerelease: false
24
+ version_requirements: *2152242240
25
+ - !ruby/object:Gem::Dependency
26
+ name: i18n
27
+ requirement: &2152240260 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2152240260
36
+ - !ruby/object:Gem::Dependency
26
37
  name: barby
38
+ requirement: &2152236320 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2152236320
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &2152234440 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  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
56
+ prerelease: false
57
+ version_requirements: *2152234440
58
+ - !ruby/object:Gem::Dependency
36
59
  name: rspec
60
+ requirement: &2152233000 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2152233000
69
+ - !ruby/object:Gem::Dependency
70
+ name: chunky_png
71
+ requirement: &2152231480 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
37
77
  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
- - !ruby/object:Gem::Dependency
78
+ prerelease: false
79
+ version_requirements: *2152231480
80
+ - !ruby/object:Gem::Dependency
46
81
  name: yard
82
+ requirement: &2152208620 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
47
88
  type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
54
- version:
89
+ prerelease: false
90
+ version_requirements: *2152208620
55
91
  description: Nice class method wrapper for Barby
56
- email: dpickett@enlightsolutions.com
92
+ email:
93
+ - dpickett@enlightsolutions.com
57
94
  executables: []
58
-
59
95
  extensions: []
60
-
61
- extra_rdoc_files:
62
- - LICENSE
63
- - README.rdoc
64
- files:
96
+ extra_rdoc_files: []
97
+ files:
65
98
  - .document
66
99
  - .gitignore
100
+ - .rspec
101
+ - .rvmrc
102
+ - .travis.yml
103
+ - Gemfile
67
104
  - LICENSE
68
105
  - README.rdoc
69
106
  - Rakefile
70
- - VERSION
71
107
  - has_barcode.gemspec
72
108
  - lib/has_barcode.rb
73
109
  - lib/has_barcode/configuration.rb
110
+ - lib/has_barcode/version.rb
74
111
  - spec/has_barcode/configuration_spec.rb
75
112
  - spec/has_barcode_spec.rb
76
113
  - spec/models/has_png_barcode.rb
77
114
  - spec/spec_helper.rb
78
- has_rdoc: true
79
- homepage: http://github.com/dpickett/has_barcode
115
+ homepage: ''
80
116
  licenses: []
81
-
82
117
  post_install_message:
83
- rdoc_options:
84
- - --charset=UTF-8
85
- require_paths:
118
+ rdoc_options: []
119
+ require_paths:
86
120
  - lib
87
- required_ruby_version: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: "0"
92
- version:
93
- required_rubygems_version: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: "0"
98
- version:
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ segments:
128
+ - 0
129
+ hash: 3109394384331655147
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ segments:
137
+ - 0
138
+ hash: 3109394384331655147
99
139
  requirements: []
100
-
101
140
  rubyforge_project:
102
- rubygems_version: 1.3.5
141
+ rubygems_version: 1.8.6
103
142
  signing_key:
104
143
  specification_version: 3
105
144
  summary: Nice class method wrapper for Barby
106
- test_files:
145
+ test_files:
107
146
  - spec/has_barcode/configuration_spec.rb
108
147
  - spec/has_barcode_spec.rb
109
148
  - spec/models/has_png_barcode.rb
110
149
  - spec/spec_helper.rb
150
+ has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1