datts_right 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/datts_right.gemspec +37 -1
- data/lib/datts_right/instance_methods.rb +12 -0
- data/spec/datts_right/add_dynamic_attributes_spec.rb +35 -22
- metadata +183 -3
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.15
|
data/datts_right.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{datts_right}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.15"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ramon Tayag"]
|
@@ -218,6 +218,18 @@ Gem::Specification.new do |s|
|
|
218
218
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
219
219
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
220
220
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
221
|
+
s.add_development_dependency(%q<autotest>, [">= 0"])
|
222
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
223
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
224
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
225
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
226
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
227
|
+
s.add_development_dependency(%q<autotest>, [">= 0"])
|
228
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
229
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
230
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
231
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
232
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
221
233
|
else
|
222
234
|
s.add_dependency(%q<datts_right>, [">= 0"])
|
223
235
|
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
@@ -378,6 +390,18 @@ Gem::Specification.new do |s|
|
|
378
390
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
379
391
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
380
392
|
s.add_dependency(%q<rcov>, [">= 0"])
|
393
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
394
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
395
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
396
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
397
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
398
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
399
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
400
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
401
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
402
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
403
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
404
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
381
405
|
end
|
382
406
|
else
|
383
407
|
s.add_dependency(%q<datts_right>, [">= 0"])
|
@@ -539,6 +563,18 @@ Gem::Specification.new do |s|
|
|
539
563
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
540
564
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
541
565
|
s.add_dependency(%q<rcov>, [">= 0"])
|
566
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
567
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
568
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
569
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
570
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
571
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
572
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
573
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
574
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
575
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
576
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
577
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
542
578
|
end
|
543
579
|
end
|
544
580
|
|
@@ -11,6 +11,17 @@ module DattsRight
|
|
11
11
|
return false
|
12
12
|
end
|
13
13
|
|
14
|
+
def add_dynamic_attribute!(name, object_type, value=nil)
|
15
|
+
key = name.to_s.underscore
|
16
|
+
return false if self.class.columns_hash[key] # if key already exists as a normal attribute
|
17
|
+
unless dynamic_attribute?(key)
|
18
|
+
new_dynamic_attribute = dynamic_attributes.create! :name => name, :attr_key => key, :object_type => object_type, "#{object_type}_value".to_sym => value
|
19
|
+
@dynamic_attributes_cache[key.to_sym] = new_dynamic_attribute
|
20
|
+
return new_dynamic_attribute
|
21
|
+
end
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
|
14
25
|
def remove_dynamic_attribute(name)
|
15
26
|
# Remove from the cache
|
16
27
|
@dynamic_attributes_cache.delete(name.to_sym)
|
@@ -163,6 +174,7 @@ module DattsRight
|
|
163
174
|
end
|
164
175
|
|
165
176
|
alias :add_datt :add_dynamic_attribute
|
177
|
+
alias :add_datt! :add_dynamic_attribute!
|
166
178
|
alias :remove_datt :remove_dynamic_attribute
|
167
179
|
alias :read_datt :read_dynamic_attribute
|
168
180
|
alias :write_datt :write_dynamic_attribute
|
@@ -1,37 +1,50 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
-
describe DattsRight
|
3
|
+
describe DattsRight do
|
4
4
|
before do
|
5
5
|
reset_database
|
6
6
|
@page = Page.create
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
describe ".add_dynamic_attribute(attr_key, object_type)" do
|
10
|
+
it "should be aliased by add_datt" do
|
11
|
+
Page.instance_method(:add_dynamic_attribute).should == Page.instance_method(:add_datt)
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
it "should add a dynamic attribute" do
|
15
|
+
@page.add_dynamic_attribute(:rocks, "string")
|
16
|
+
@page.dynamic_attribute_details(:rocks).value.should be_nil
|
17
|
+
@page.add_dynamic_attribute(:rock, "string", "123")
|
18
|
+
@page.read_datt(:rock).should == "123"
|
19
|
+
@page.dynamic_attribute_details(:rock).value.should == "123"
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
it "should ignore when trying to add same attribute" do
|
23
|
+
@page.add_dynamic_attribute(:rocks, "string")
|
24
|
+
@page.add_dynamic_attribute(:rocks, "integer")
|
25
|
+
@page.dynamic_attribute_details(:rocks).object_type.should == "string"
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
it "should return false if the method that is being added already exists" do
|
29
|
+
@page.add_dynamic_attribute(:name, "text").should be_false
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not make any changes to the original attribute" do
|
33
|
+
@page.update_attribute(:name, "juno")
|
34
|
+
@page.add_dynamic_attribute(:name, "text")
|
35
|
+
@page.name.should == "juno"
|
36
|
+
end
|
29
37
|
end
|
30
38
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
39
|
+
describe ".add_dynamic_attribute!" do
|
40
|
+
it "should be aliased by add_datt!" do
|
41
|
+
Page.instance_method(:add_dynamic_attribute!).should == Page.instance_method(:add_datt!)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should create the dynamic attribute, not waiting to save the attributable record" do
|
45
|
+
@page.add_dynamic_attribute!(:price, "integer", 200)
|
46
|
+
Page.last.price.should == 200
|
47
|
+
end
|
35
48
|
end
|
36
49
|
end
|
37
50
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datts_right
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 15
|
10
|
+
version: 0.0.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ramon Tayag
|
@@ -2404,6 +2404,186 @@ dependencies:
|
|
2404
2404
|
name: rcov
|
2405
2405
|
version_requirements: *id159
|
2406
2406
|
prerelease: false
|
2407
|
+
- !ruby/object:Gem::Dependency
|
2408
|
+
type: :development
|
2409
|
+
requirement: &id160 !ruby/object:Gem::Requirement
|
2410
|
+
none: false
|
2411
|
+
requirements:
|
2412
|
+
- - ">="
|
2413
|
+
- !ruby/object:Gem::Version
|
2414
|
+
hash: 3
|
2415
|
+
segments:
|
2416
|
+
- 0
|
2417
|
+
version: "0"
|
2418
|
+
name: autotest
|
2419
|
+
version_requirements: *id160
|
2420
|
+
prerelease: false
|
2421
|
+
- !ruby/object:Gem::Dependency
|
2422
|
+
type: :development
|
2423
|
+
requirement: &id161 !ruby/object:Gem::Requirement
|
2424
|
+
none: false
|
2425
|
+
requirements:
|
2426
|
+
- - ">="
|
2427
|
+
- !ruby/object:Gem::Version
|
2428
|
+
hash: 3
|
2429
|
+
segments:
|
2430
|
+
- 0
|
2431
|
+
version: "0"
|
2432
|
+
name: sqlite3
|
2433
|
+
version_requirements: *id161
|
2434
|
+
prerelease: false
|
2435
|
+
- !ruby/object:Gem::Dependency
|
2436
|
+
type: :development
|
2437
|
+
requirement: &id162 !ruby/object:Gem::Requirement
|
2438
|
+
none: false
|
2439
|
+
requirements:
|
2440
|
+
- - ~>
|
2441
|
+
- !ruby/object:Gem::Version
|
2442
|
+
hash: 3
|
2443
|
+
segments:
|
2444
|
+
- 2
|
2445
|
+
- 3
|
2446
|
+
- 0
|
2447
|
+
version: 2.3.0
|
2448
|
+
name: rspec
|
2449
|
+
version_requirements: *id162
|
2450
|
+
prerelease: false
|
2451
|
+
- !ruby/object:Gem::Dependency
|
2452
|
+
type: :development
|
2453
|
+
requirement: &id163 !ruby/object:Gem::Requirement
|
2454
|
+
none: false
|
2455
|
+
requirements:
|
2456
|
+
- - ~>
|
2457
|
+
- !ruby/object:Gem::Version
|
2458
|
+
hash: 23
|
2459
|
+
segments:
|
2460
|
+
- 1
|
2461
|
+
- 0
|
2462
|
+
- 0
|
2463
|
+
version: 1.0.0
|
2464
|
+
name: bundler
|
2465
|
+
version_requirements: *id163
|
2466
|
+
prerelease: false
|
2467
|
+
- !ruby/object:Gem::Dependency
|
2468
|
+
type: :development
|
2469
|
+
requirement: &id164 !ruby/object:Gem::Requirement
|
2470
|
+
none: false
|
2471
|
+
requirements:
|
2472
|
+
- - ~>
|
2473
|
+
- !ruby/object:Gem::Version
|
2474
|
+
hash: 7
|
2475
|
+
segments:
|
2476
|
+
- 1
|
2477
|
+
- 5
|
2478
|
+
- 2
|
2479
|
+
version: 1.5.2
|
2480
|
+
name: jeweler
|
2481
|
+
version_requirements: *id164
|
2482
|
+
prerelease: false
|
2483
|
+
- !ruby/object:Gem::Dependency
|
2484
|
+
type: :development
|
2485
|
+
requirement: &id165 !ruby/object:Gem::Requirement
|
2486
|
+
none: false
|
2487
|
+
requirements:
|
2488
|
+
- - ">="
|
2489
|
+
- !ruby/object:Gem::Version
|
2490
|
+
hash: 3
|
2491
|
+
segments:
|
2492
|
+
- 0
|
2493
|
+
version: "0"
|
2494
|
+
name: rcov
|
2495
|
+
version_requirements: *id165
|
2496
|
+
prerelease: false
|
2497
|
+
- !ruby/object:Gem::Dependency
|
2498
|
+
type: :development
|
2499
|
+
requirement: &id166 !ruby/object:Gem::Requirement
|
2500
|
+
none: false
|
2501
|
+
requirements:
|
2502
|
+
- - ">="
|
2503
|
+
- !ruby/object:Gem::Version
|
2504
|
+
hash: 3
|
2505
|
+
segments:
|
2506
|
+
- 0
|
2507
|
+
version: "0"
|
2508
|
+
name: autotest
|
2509
|
+
version_requirements: *id166
|
2510
|
+
prerelease: false
|
2511
|
+
- !ruby/object:Gem::Dependency
|
2512
|
+
type: :development
|
2513
|
+
requirement: &id167 !ruby/object:Gem::Requirement
|
2514
|
+
none: false
|
2515
|
+
requirements:
|
2516
|
+
- - ">="
|
2517
|
+
- !ruby/object:Gem::Version
|
2518
|
+
hash: 3
|
2519
|
+
segments:
|
2520
|
+
- 0
|
2521
|
+
version: "0"
|
2522
|
+
name: sqlite3
|
2523
|
+
version_requirements: *id167
|
2524
|
+
prerelease: false
|
2525
|
+
- !ruby/object:Gem::Dependency
|
2526
|
+
type: :development
|
2527
|
+
requirement: &id168 !ruby/object:Gem::Requirement
|
2528
|
+
none: false
|
2529
|
+
requirements:
|
2530
|
+
- - ~>
|
2531
|
+
- !ruby/object:Gem::Version
|
2532
|
+
hash: 3
|
2533
|
+
segments:
|
2534
|
+
- 2
|
2535
|
+
- 3
|
2536
|
+
- 0
|
2537
|
+
version: 2.3.0
|
2538
|
+
name: rspec
|
2539
|
+
version_requirements: *id168
|
2540
|
+
prerelease: false
|
2541
|
+
- !ruby/object:Gem::Dependency
|
2542
|
+
type: :development
|
2543
|
+
requirement: &id169 !ruby/object:Gem::Requirement
|
2544
|
+
none: false
|
2545
|
+
requirements:
|
2546
|
+
- - ~>
|
2547
|
+
- !ruby/object:Gem::Version
|
2548
|
+
hash: 23
|
2549
|
+
segments:
|
2550
|
+
- 1
|
2551
|
+
- 0
|
2552
|
+
- 0
|
2553
|
+
version: 1.0.0
|
2554
|
+
name: bundler
|
2555
|
+
version_requirements: *id169
|
2556
|
+
prerelease: false
|
2557
|
+
- !ruby/object:Gem::Dependency
|
2558
|
+
type: :development
|
2559
|
+
requirement: &id170 !ruby/object:Gem::Requirement
|
2560
|
+
none: false
|
2561
|
+
requirements:
|
2562
|
+
- - ~>
|
2563
|
+
- !ruby/object:Gem::Version
|
2564
|
+
hash: 7
|
2565
|
+
segments:
|
2566
|
+
- 1
|
2567
|
+
- 5
|
2568
|
+
- 2
|
2569
|
+
version: 1.5.2
|
2570
|
+
name: jeweler
|
2571
|
+
version_requirements: *id170
|
2572
|
+
prerelease: false
|
2573
|
+
- !ruby/object:Gem::Dependency
|
2574
|
+
type: :development
|
2575
|
+
requirement: &id171 !ruby/object:Gem::Requirement
|
2576
|
+
none: false
|
2577
|
+
requirements:
|
2578
|
+
- - ">="
|
2579
|
+
- !ruby/object:Gem::Version
|
2580
|
+
hash: 3
|
2581
|
+
segments:
|
2582
|
+
- 0
|
2583
|
+
version: "0"
|
2584
|
+
name: rcov
|
2585
|
+
version_requirements: *id171
|
2586
|
+
prerelease: false
|
2407
2587
|
description: Creates a separate table that saves all your dynamic attributes.
|
2408
2588
|
email: ramon@tayag.net
|
2409
2589
|
executables: []
|