flattener 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -61,10 +61,8 @@ I know what you think. "I can do that with a simple delegate call". Indeed, but
61
61
  has_one :payment_profile
62
62
 
63
63
  flat :payment_profile do
64
-
65
64
  attributes :credit_card, :expiration_date
66
-
67
- flat :address do
65
+ flat :address, build: proc { proxy_payment_profile.build_address } do
68
66
  attribute :address_line_1
69
67
  attribute :address_line_2
70
68
  end
@@ -85,6 +83,36 @@ And this way getting something really simple:
85
83
  payment.valid? #=> false
86
84
  payment.errors[:payment_profile_address_line_1] #=> ".... is required, blah..."
87
85
 
86
+ Prefix is optional, and changeable:
87
+
88
+ class Payment < ActiveRecord::Base
89
+
90
+ include Flattener
91
+
92
+ has_one :payment_profile
93
+
94
+ flat :payment_profile, prefix: "pp" do
95
+ attributes :credit_card, :expiration_date
96
+ end
97
+ end
98
+
99
+ payment = Payment.new
100
+ payment.pp_credit_card = "XXXX-XXXX-XXXX-XXXX"
101
+ payment.pp_credit_card # => "XXXX-XXXX-XXXX-XXXX"
102
+
103
+ You can use this also as a presenter (or something like that):
104
+
105
+ class PaymentBuilder < Flattener::Base
106
+ flat :payment_profile, prefix: "" do
107
+ attributes :credit_card, :expiration_date
108
+ end
109
+ end
110
+
111
+ payment = PaymentBuilder.new :credit_card => "XXXX-XXXX-XXXX-XXXX"
112
+ payment.credit_card # => "XXXX-XXXX-XXXX-XXXX"
113
+
114
+ You wonder why is this useful? May be you have something really complex on your app, but you want to expose it (to the view) in a simpler way, and only allowing some properties.
115
+
88
116
  So what is this gem doing?
89
117
 
90
118
  * It builds the flattened objects automatically, or the way you want (configuration option).
data/flattener.gemspec CHANGED
@@ -4,9 +4,9 @@ require File.expand_path('../lib/flattener/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Lucas Florio"]
6
6
  gem.email = ["lucasefe@gmail.com"]
7
- gem.description = %q{Allows to flat an object and his children (ActiveRecord based) into one level, so you create them all without building a complex form. }
7
+ gem.description = %q{Allows to flat an object and his children (ActiveRecord based) into one level, so you can create them all without building a complex form. }
8
8
  gem.summary = gem.description
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/lucasefe/flattener"
10
10
 
11
11
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
12
  gem.files = `git ls-files`.split("\n")
@@ -1,3 +1,3 @@
1
1
  module Flattener
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flattener
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70174276620400 !ruby/object:Gem::Requirement
16
+ requirement: &70149869218620 !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: *70174276620400
24
+ version_requirements: *70149869218620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70174276619820 !ruby/object:Gem::Requirement
27
+ requirement: &70149869218000 !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: :development
34
34
  prerelease: false
35
- version_requirements: *70174276619820
35
+ version_requirements: *70149869218000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70174276619140 !ruby/object:Gem::Requirement
38
+ requirement: &70149869217360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70174276619140
46
+ version_requirements: *70149869217360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shoulda
49
- requirement: &70174276618720 !ruby/object:Gem::Requirement
49
+ requirement: &70149869216940 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70174276618720
57
+ version_requirements: *70149869216940
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-rspec
60
- requirement: &70174276618300 !ruby/object:Gem::Requirement
60
+ requirement: &70149869216520 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,9 +65,9 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70174276618300
68
+ version_requirements: *70149869216520
69
69
  description: ! 'Allows to flat an object and his children (ActiveRecord based) into
70
- one level, so you create them all without building a complex form. '
70
+ one level, so you can create them all without building a complex form. '
71
71
  email:
72
72
  - lucasefe@gmail.com
73
73
  executables: []
@@ -90,7 +90,7 @@ files:
90
90
  - spec/lib/flattener/base_spec.rb
91
91
  - spec/lib/flattener/configurator_spec.rb
92
92
  - spec/spec_helper.rb
93
- homepage: ''
93
+ homepage: https://github.com/lucasefe/flattener
94
94
  licenses: []
95
95
  post_install_message:
96
96
  rdoc_options: []
@@ -114,7 +114,7 @@ rubygems_version: 1.8.15
114
114
  signing_key:
115
115
  specification_version: 3
116
116
  summary: Allows to flat an object and his children (ActiveRecord based) into one level,
117
- so you create them all without building a complex form.
117
+ so you can create them all without building a complex form.
118
118
  test_files:
119
119
  - spec/lib/flattener/base_spec.rb
120
120
  - spec/lib/flattener/configurator_spec.rb