bricks 0.4.0 → 0.4.1
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/History.md +6 -0
 - data/README.md +15 -6
 - data/VERSION +1 -1
 - data/bricks.gemspec +2 -2
 - data/lib/bricks/builder.rb +7 -2
 - data/lib/bricks/builder_set.rb +4 -4
 - data/spec/bricks_spec.rb +14 -8
 - metadata +3 -3
 
    
        data/History.md
    CHANGED
    
    | 
         @@ -1,6 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            History
         
     | 
| 
       2 
2 
     | 
    
         
             
            =======
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
      
 4 
     | 
    
         
            +
            0.4.1
         
     | 
| 
      
 5 
     | 
    
         
            +
            -----
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            * You no longer need to place builders for classes used in associations before the builders for objects that declare those associations.
         
     | 
| 
      
 8 
     | 
    
         
            +
            * Fixed: you can now create builders for *-to-many associations using only the default attributes.
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
       4 
10 
     | 
    
         
             
            0.4.0
         
     | 
| 
       5 
11 
     | 
    
         
             
            -----
         
     | 
| 
       6 
12 
     | 
    
         | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -155,13 +155,22 @@ There is a slight difference between using `~` and `?`. `~` will permanently cha 
     | 
|
| 
       155 
155 
     | 
    
         | 
| 
       156 
156 
     | 
    
         
             
            #### One-to-many, Many-to-many (has many, has and belongs to many)
         
     | 
| 
       157 
157 
     | 
    
         | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
                  builder Article do
         
     | 
| 
       160 
     | 
    
         
            -
                    # ...
         
     | 
| 
      
 158 
     | 
    
         
            +
            You can create several objects for a *-to-many association by calling the method `#build` on the association:
         
     | 
| 
       161 
159 
     | 
    
         | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
                   
     | 
| 
      
 160 
     | 
    
         
            +
                builder Article do
         
     | 
| 
      
 161 
     | 
    
         
            +
                  # readers association will have 3 records
         
     | 
| 
      
 162 
     | 
    
         
            +
                  3.times { readers.build }
         
     | 
| 
      
 163 
     | 
    
         
            +
                end
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
            Upon generation, this will add 3 records with their attributes set to the defaults defined in the association class' builder. 
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
            If you want to further customize each builder in the association, you can omit the `#build` method call:
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
                builder Article do
         
     | 
| 
      
 170 
     | 
    
         
            +
                  # ...
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
                  # readers association will have 3 records
         
     | 
| 
      
 173 
     | 
    
         
            +
                  %w(Tom Dick Harry).each { |r| readers.name(r) }
         
     | 
| 
       165 
174 
     | 
    
         
             
                end
         
     | 
| 
       166 
175 
     | 
    
         | 
| 
       167 
176 
     | 
    
         
             
            Each call to the *-to-many association name will add a new builder, which you can then further customize:
         
     | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.4. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.4.1
         
     | 
    
        data/bricks.gemspec
    CHANGED
    
    | 
         @@ -5,11 +5,11 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = %q{bricks}
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.4. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.4.1"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["David Leal"]
         
     | 
| 
       12 
     | 
    
         
            -
              s.date = %q{2011-06- 
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = %q{2011-06-23}
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.email = %q{david@mojotech.com}
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.extra_rdoc_files = [
         
     | 
| 
       15 
15 
     | 
    
         
             
                "LICENSE.txt",
         
     | 
    
        data/lib/bricks/builder.rb
    CHANGED
    
    | 
         @@ -24,6 +24,8 @@ module Bricks 
     | 
|
| 
       24 
24 
     | 
    
         
             
                end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
                def derive(args = {})
         
     | 
| 
      
 27 
     | 
    
         
            +
                  build_attrs
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       27 
29 
     | 
    
         
             
                  klass  = args[:class] || @class
         
     | 
| 
       28 
30 
     | 
    
         
             
                  save   = args.has_key?(:save) ? args[:save] : @save
         
     | 
| 
       29 
31 
     | 
    
         
             
                  search = args.has_key?(:search) ? args[:search] : @search
         
     | 
| 
         @@ -43,10 +45,9 @@ module Bricks 
     | 
|
| 
       43 
45 
     | 
    
         
             
                  @traits = traits ? Module.new { include traits } : Module.new
         
     | 
| 
       44 
46 
     | 
    
         
             
                  @save   = save
         
     | 
| 
       45 
47 
     | 
    
         
             
                  @search = search
         
     | 
| 
      
 48 
     | 
    
         
            +
                  @block  = block
         
     | 
| 
       46 
49 
     | 
    
         | 
| 
       47 
50 
     | 
    
         
             
                  extend @traits
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                  instance_eval &block if block_given?
         
     | 
| 
       50 
51 
     | 
    
         
             
                end
         
     | 
| 
       51 
52 
     | 
    
         | 
| 
       52 
53 
     | 
    
         
             
                def generate(opts = {})
         
     | 
| 
         @@ -158,5 +159,9 @@ module Bricks 
     | 
|
| 
       158 
159 
     | 
    
         
             
                          "No value or block given and not an association: #{name}."
         
     | 
| 
       159 
160 
     | 
    
         
             
                  end
         
     | 
| 
       160 
161 
     | 
    
         
             
                end
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
                def build_attrs
         
     | 
| 
      
 164 
     | 
    
         
            +
                  instance_eval &@block if @block && @attrs.empty?
         
     | 
| 
      
 165 
     | 
    
         
            +
                end
         
     | 
| 
       161 
166 
     | 
    
         
             
              end
         
     | 
| 
       162 
167 
     | 
    
         
             
            end
         
     | 
    
        data/lib/bricks/builder_set.rb
    CHANGED
    
    | 
         @@ -4,11 +4,11 @@ module Bricks 
     | 
|
| 
       4 
4 
     | 
    
         
             
              class BuilderSet
         
     | 
| 
       5 
5 
     | 
    
         
             
                include Bricks::DSL
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
                def build(klass)
         
     | 
| 
      
 7 
     | 
    
         
            +
                def build(klass = @class)
         
     | 
| 
       8 
8 
     | 
    
         
             
                  (@builders << super).last
         
     | 
| 
       9 
9 
     | 
    
         
             
                end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                def build!(klass)
         
     | 
| 
      
 11 
     | 
    
         
            +
                def build!(klass = @class)
         
     | 
| 
       12 
12 
     | 
    
         
             
                  (@builders << super).last
         
     | 
| 
       13 
13 
     | 
    
         
             
                end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
         @@ -16,11 +16,11 @@ module Bricks 
     | 
|
| 
       16 
16 
     | 
    
         
             
                  @builders.clear
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                def create(klass)
         
     | 
| 
      
 19 
     | 
    
         
            +
                def create(klass = @class)
         
     | 
| 
       20 
20 
     | 
    
         
             
                  (@builders << super).last
         
     | 
| 
       21 
21 
     | 
    
         
             
                end
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                def create!(klass)
         
     | 
| 
      
 23 
     | 
    
         
            +
                def create!(klass = @class)
         
     | 
| 
       24 
24 
     | 
    
         
             
                  (@builders << super).last
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
       26 
26 
     | 
    
         | 
    
        data/spec/bricks_spec.rb
    CHANGED
    
    | 
         @@ -11,14 +11,6 @@ describe Bricks do 
     | 
|
| 
       11 
11 
     | 
    
         
             
                    start_date Date.new(1900, 1, 1)
         
     | 
| 
       12 
12 
     | 
    
         
             
                  end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                  builder Newspaper do
         
     | 
| 
       15 
     | 
    
         
            -
                    name "The Daily Planet"
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                    trait :daily_bugle do
         
     | 
| 
       18 
     | 
    
         
            -
                      name "The Daily Bugle"
         
     | 
| 
       19 
     | 
    
         
            -
                    end
         
     | 
| 
       20 
     | 
    
         
            -
                  end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
14 
     | 
    
         
             
                  builder Article do
         
     | 
| 
       23 
15 
     | 
    
         
             
                    author   'Jack Jupiter'
         
     | 
| 
       24 
16 
     | 
    
         
             
                    title    'a title'
         
     | 
| 
         @@ -53,6 +45,14 @@ describe Bricks do 
     | 
|
| 
       53 
45 
     | 
    
         
             
                      %w(Tom Dick Harry).each { |n| readers.name(n) }
         
     | 
| 
       54 
46 
     | 
    
         
             
                    end
         
     | 
| 
       55 
47 
     | 
    
         
             
                  end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  builder Newspaper do
         
     | 
| 
      
 50 
     | 
    
         
            +
                    name "The Daily Planet"
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                    trait :daily_bugle do
         
     | 
| 
      
 53 
     | 
    
         
            +
                      name "The Daily Bugle"
         
     | 
| 
      
 54 
     | 
    
         
            +
                    end
         
     | 
| 
      
 55 
     | 
    
         
            +
                  end
         
     | 
| 
       56 
56 
     | 
    
         
             
                end
         
     | 
| 
       57 
57 
     | 
    
         
             
              end
         
     | 
| 
       58 
58 
     | 
    
         | 
| 
         @@ -197,6 +197,12 @@ describe Bricks do 
     | 
|
| 
       197 
197 
     | 
    
         
             
                    r.name
         
     | 
| 
       198 
198 
     | 
    
         
             
                  }.should == %w(Tom Dick Harry)
         
     | 
| 
       199 
199 
     | 
    
         
             
                end
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
                it "creates records with default attributes" do
         
     | 
| 
      
 202 
     | 
    
         
            +
                  a = create(Article).tap { |b| 2.times { b.readers.build } }.generate
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
      
 204 
     | 
    
         
            +
                  a.should have(5).readers
         
     | 
| 
      
 205 
     | 
    
         
            +
                end
         
     | 
| 
       200 
206 
     | 
    
         
             
              end
         
     | 
| 
       201 
207 
     | 
    
         | 
| 
       202 
208 
     | 
    
         
             
              describe "builder inheritance" do
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: bricks
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 0.4. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.4.1
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors: 
         
     | 
| 
       8 
8 
     | 
    
         
             
            - David Leal
         
     | 
| 
         @@ -10,7 +10,7 @@ autorequire: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            date: 2011-06- 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2011-06-23 00:00:00 +01:00
         
     | 
| 
       14 
14 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       15 
15 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       16 
16 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -101,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       101 
101 
     | 
    
         
             
              requirements: 
         
     | 
| 
       102 
102 
     | 
    
         
             
              - - ">="
         
     | 
| 
       103 
103 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       104 
     | 
    
         
            -
                  hash: - 
     | 
| 
      
 104 
     | 
    
         
            +
                  hash: -949772447
         
     | 
| 
       105 
105 
     | 
    
         
             
                  segments: 
         
     | 
| 
       106 
106 
     | 
    
         
             
                  - 0
         
     | 
| 
       107 
107 
     | 
    
         
             
                  version: "0"
         
     |