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 +1 -1
- data/has_price.gemspec +21 -29
- data/lib/has_price.rb +23 -9
- data/lib/has_price/price_builder.rb +12 -12
- data/lib/has_price/railtie.rb +7 -0
- metadata +29 -22
- data/.gitignore +0 -21
- data/rails/init.rb +0 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/has_price.gemspec
CHANGED
@@ -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
|
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.
|
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{
|
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
|
-
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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.
|
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
|
data/lib/has_price.rb
CHANGED
@@ -1,14 +1,28 @@
|
|
1
|
-
|
2
|
-
|
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
|
5
|
-
|
12
|
+
unless Array.respond_to?(:extract_options!)
|
13
|
+
class Array
|
14
|
+
include HasPrice::CoreExtensions::Array
|
15
|
+
end
|
6
16
|
end
|
7
17
|
|
8
|
-
unless
|
9
|
-
|
18
|
+
unless String.respond_to?(:underscore)
|
19
|
+
class String
|
20
|
+
include HasPrice::CoreExtensions::String
|
21
|
+
end
|
10
22
|
end
|
11
23
|
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
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
|
-
|
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:
|
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
|
-
|
18
|
-
|
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
|
-
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
25
32
|
- !ruby/object:Gem::Dependency
|
26
33
|
name: rr
|
27
|
-
|
28
|
-
|
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
|
-
|
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
|
-
-
|
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
|
-
|
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.
|
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
|
-
|
92
|
-
- test/test_has_price.rb
|
93
|
-
- test/test_price.rb
|
94
|
-
- test/test_price_builder.rb
|
100
|
+
test_files: []
|
101
|
+
|
data/.gitignore
DELETED
data/rails/init.rb
DELETED