has_price 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.2.0
@@ -1,51 +1,43 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_price}
8
- s.version = "1.1.1"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Maxim Chernyak"]
12
- s.date = %q{2010-01-18}
12
+ s.date = %q{2012-05-22}
13
13
  s.description = %q{A convenient DSL for defining complex price reader/serializer in a class and organizing a price breakdown. Price can be declared with items and groups which depend on other attributes. Price is a very simple subclass of Hash. This provides for easy serialization and flexibility in case of implementation changes. This way you can conveniently store the whole price breakdown in your serialized receipts. It also provides magic methods for convenient access, but can be fully treated as a regular Hash with some sprinkles on top.}
14
14
  s.email = %q{max@bitsonnet.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.md"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
- ".gitignore",
21
- "LICENSE",
22
- "README.md",
23
- "Rakefile",
24
- "VERSION",
25
- "has_price.gemspec",
26
- "lib/has_price.rb",
27
- "lib/has_price/core_extensions/array.rb",
28
- "lib/has_price/core_extensions/string.rb",
29
- "lib/has_price/has_price.rb",
30
- "lib/has_price/price.rb",
31
- "lib/has_price/price_builder.rb",
32
- "rails/init.rb",
33
- "test/helper.rb",
34
- "test/test_has_price.rb",
35
- "test/test_price.rb",
36
- "test/test_price_builder.rb"
20
+ "LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "has_price.gemspec",
25
+ "lib/has_price.rb",
26
+ "lib/has_price/core_extensions/array.rb",
27
+ "lib/has_price/core_extensions/string.rb",
28
+ "lib/has_price/has_price.rb",
29
+ "lib/has_price/price.rb",
30
+ "lib/has_price/price_builder.rb",
31
+ "lib/has_price/railtie.rb",
32
+ "test/helper.rb",
33
+ "test/test_has_price.rb",
34
+ "test/test_price.rb",
35
+ "test/test_price_builder.rb"
37
36
  ]
38
37
  s.homepage = %q{http://github.com/maxim/has_price}
39
- s.rdoc_options = ["--charset=UTF-8"]
40
38
  s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.3.5}
39
+ s.rubygems_version = %q{1.3.6}
42
40
  s.summary = %q{Provides a convenient DSL for organizing a price breakdown in a class.}
43
- s.test_files = [
44
- "test/helper.rb",
45
- "test/test_has_price.rb",
46
- "test/test_price.rb",
47
- "test/test_price_builder.rb"
48
- ]
49
41
 
50
42
  if s.respond_to? :specification_version then
51
43
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -1,14 +1,28 @@
1
- require File.dirname(__FILE__) + "/has_price/core_extensions/array.rb"
2
- require File.dirname(__FILE__) + "/has_price/core_extensions/string.rb"
1
+ unless Kernel.respond_to?(:require_relative)
2
+ module Kernel
3
+ def require_relative(path)
4
+ require File.join(File.dirname(caller[0]), path.to_str)
5
+ end
6
+ end
7
+ end
8
+
9
+ require_relative 'has_price/core_extensions/array.rb'
10
+ require_relative 'has_price/core_extensions/string.rb'
3
11
 
4
- unless ["extract_options!", :extract_options!].any?{|meth| Array.instance_methods.include?(meth)}
5
- Array.send :include, HasPrice::CoreExtensions::Array
12
+ unless Array.respond_to?(:extract_options!)
13
+ class Array
14
+ include HasPrice::CoreExtensions::Array
15
+ end
6
16
  end
7
17
 
8
- unless ["underscore", :underscore].any?{|meth| String.instance_methods.include?(meth)}
9
- String.send :include, HasPrice::CoreExtensions::String
18
+ unless String.respond_to?(:underscore)
19
+ class String
20
+ include HasPrice::CoreExtensions::String
21
+ end
10
22
  end
11
23
 
12
- require File.dirname(__FILE__) + "/has_price/price.rb"
13
- require File.dirname(__FILE__) + "/has_price/price_builder.rb"
14
- require File.dirname(__FILE__) + "/has_price/has_price.rb"
24
+ require_relative 'has_price/price.rb'
25
+ require_relative 'has_price/price_builder.rb'
26
+ require_relative 'has_price/has_price.rb'
27
+
28
+ require_relative 'has_price/railtie' if defined?(Rails)
@@ -1,7 +1,7 @@
1
1
  module HasPrice
2
2
  class PriceBuilder
3
3
  attr_reader :price
4
-
4
+
5
5
  # Creates PriceBuilder on a target object.
6
6
  #
7
7
  # @param [Object] object the target object on which price is being built.
@@ -10,11 +10,11 @@ module HasPrice
10
10
  @current_nesting_level = @price
11
11
  @object = object
12
12
  end
13
-
13
+
14
14
  # Adds price item to the current nesting level of price definition.
15
15
  #
16
16
  # @param [#to_hash, #to_i] price an integer representing amount for this price item.
17
- # Alternatively, anything that responds to #to_hash can be used,
17
+ # Alternatively, anything that responds to #to_hash can be used,
18
18
  # and will be treated as a group named with item_name.
19
19
  # @param [#to_s] item_name name for the provided price item or group.
20
20
  #
@@ -22,9 +22,9 @@ module HasPrice
22
22
  def item(price, item_name)
23
23
  @current_nesting_level[item_name.to_s] = price.respond_to?(:to_hash) ? price.to_hash : price.to_i
24
24
  end
25
-
25
+
26
26
  # Adds price group to the current nesting level of price definition.
27
- # Groups are useful for price breakdown categorization and easy subtotal values.
27
+ # Groups are useful for price breakdown categorization and easy subtotal values.
28
28
  #
29
29
  # @example Using group subtotals
30
30
  # class Product
@@ -54,35 +54,35 @@ module HasPrice
54
54
  # @see #item
55
55
  def group(group_name, &block)
56
56
  group_key = group_name.to_s
57
-
57
+
58
58
  @current_nesting_level[group_key] ||= {}
59
-
59
+
60
60
  if block_given?
61
61
  within_group(group_key) do
62
62
  instance_eval &block
63
63
  end
64
64
  end
65
65
  end
66
-
66
+
67
67
  # Delegates all missing methods to the target object.
68
68
  def method_missing(meth, *args, &block)
69
69
  @object.send(meth, *args, &block)
70
70
  end
71
71
 
72
- private
72
+ private
73
73
  def within_group(group_name)
74
74
  step_into group_name
75
75
  yield
76
76
  step_out
77
77
  end
78
-
78
+
79
79
  def step_into(group_name)
80
80
  @original_nesting_level = @current_nesting_level
81
81
  @current_nesting_level = @current_nesting_level[group_name]
82
82
  end
83
-
83
+
84
84
  def step_out
85
85
  @current_nesting_level = @original_nesting_level
86
86
  end
87
87
  end
88
- end
88
+ end
@@ -0,0 +1,7 @@
1
+ module HasPrice
2
+ class Railtie < Rails::Railtie
3
+ initializer "has_price.configure_rails_initialization" do
4
+ ActiveRecord::Base.extend HasPrice
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_price
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 2
8
+ - 0
9
+ version: 1.2.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Maxim Chernyak
@@ -9,29 +14,33 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-18 00:00:00 -05:00
17
+ date: 2012-05-22 00:00:00 +04:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: shoulda
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :development
31
+ version_requirements: *id001
25
32
  - !ruby/object:Gem::Dependency
26
33
  name: rr
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
33
41
  version: "0"
34
- version:
42
+ type: :development
43
+ version_requirements: *id002
35
44
  description: A convenient DSL for defining complex price reader/serializer in a class and organizing a price breakdown. Price can be declared with items and groups which depend on other attributes. Price is a very simple subclass of Hash. This provides for easy serialization and flexibility in case of implementation changes. This way you can conveniently store the whole price breakdown in your serialized receipts. It also provides magic methods for convenient access, but can be fully treated as a regular Hash with some sprinkles on top.
36
45
  email: max@bitsonnet.com
37
46
  executables: []
@@ -42,7 +51,6 @@ extra_rdoc_files:
42
51
  - LICENSE
43
52
  - README.md
44
53
  files:
45
- - .gitignore
46
54
  - LICENSE
47
55
  - README.md
48
56
  - Rakefile
@@ -54,7 +62,7 @@ files:
54
62
  - lib/has_price/has_price.rb
55
63
  - lib/has_price/price.rb
56
64
  - lib/has_price/price_builder.rb
57
- - rails/init.rb
65
+ - lib/has_price/railtie.rb
58
66
  - test/helper.rb
59
67
  - test/test_has_price.rb
60
68
  - test/test_price.rb
@@ -64,31 +72,30 @@ homepage: http://github.com/maxim/has_price
64
72
  licenses: []
65
73
 
66
74
  post_install_message:
67
- rdoc_options:
68
- - --charset=UTF-8
75
+ rdoc_options: []
76
+
69
77
  require_paths:
70
78
  - lib
71
79
  required_ruby_version: !ruby/object:Gem::Requirement
72
80
  requirements:
73
81
  - - ">="
74
82
  - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
75
85
  version: "0"
76
- version:
77
86
  required_rubygems_version: !ruby/object:Gem::Requirement
78
87
  requirements:
79
88
  - - ">="
80
89
  - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
81
92
  version: "0"
82
- version:
83
93
  requirements: []
84
94
 
85
95
  rubyforge_project:
86
- rubygems_version: 1.3.5
96
+ rubygems_version: 1.3.6
87
97
  signing_key:
88
98
  specification_version: 3
89
99
  summary: Provides a convenient DSL for organizing a price breakdown in a class.
90
- test_files:
91
- - test/helper.rb
92
- - test/test_has_price.rb
93
- - test/test_price.rb
94
- - test/test_price_builder.rb
100
+ test_files: []
101
+
data/.gitignore DELETED
@@ -1,21 +0,0 @@
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
- doc
20
- pkg
21
- .yardoc
@@ -1,3 +0,0 @@
1
- require 'has_price'
2
-
3
- ActiveRecord::Base.extend HasPrice::HasPrice