moosex 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81a1d69a0ea74ca118361a16b549201215fd255e
4
- data.tar.gz: 562b285c934e2e1a798c89b4ff02afd9af4c3754
3
+ metadata.gz: 2bc3f32eac599e2895f68118cdfab74c5e91f014
4
+ data.tar.gz: d5934a0cd121ba31c4f2e9596d7ec52873e9cd63
5
5
  SHA512:
6
- metadata.gz: a68c128bb6fffdcb6c50eb174d486e963919e031c111ffe537f89a517fda547e62180abfcf96a096c310790b48fe5759e2cb2846745ef7267f94f30bf9fd5fbf
7
- data.tar.gz: 31fa71baa921d302d7603197e6dca60c0f423064e9e2eccfcab0d47f3bf463a88a2343e28979c5ea89021a40d6815cda02b4218e31c7f317ed375b62006f45ad
6
+ metadata.gz: f09c0292f96d3754959c80646c88e658d6adddc58b4a3b2e642e9a5d32c4e80d11f09688f74b99607ad1b74293d121d49c8f3f9097404dc3d367e91d972b07d3
7
+ data.tar.gz: f82a77fd8af5315b2c7e6671df97f9870648a81c7ab4c8c732cd0d35cf35605fcbbc3c4ba2955da96a7907a01b69b10d7e0d6a9a0822f76fd5211c31d95c20c0
data/Changelog CHANGED
@@ -1,3 +1,6 @@
1
+ 0.0.21 - 2014-02-16
2
+ - simplify plugins and add prepare method #80
3
+
1
4
  0.0.20 - 2014-02-16
2
5
  - add plugins Chained and ExpiredAttribute #76
3
6
  - remove experimental traits, add Expire
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moosex (0.0.20)
4
+ moosex (0.0.21)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -18,6 +18,7 @@ But the objetive of MooseX is different: this is a toolbox to create Classes bas
18
18
  - lazy attributes
19
19
  - roles / abstract classes / interfaces
20
20
  - traits / monads
21
+ - plugins
21
22
  - parameterized roles
22
23
  - composable type check
23
24
  - events
@@ -589,7 +590,23 @@ sleep(3)
589
590
  page.session.valid? # => false
590
591
  ```
591
592
 
592
- See plugin "ExpiredAttribute" for a more clean interface (without this ugly coerce)!
593
+ If you want avoid the ugly coerce, you can specify one expired time using the method 'with'.
594
+
595
+ ```ruby
596
+ requires 'moosex'
597
+ requires 'moosex/traits'
598
+
599
+ class MyHomePage
600
+ include MooseX
601
+ has session: {
602
+ is: :rw,
603
+ default: -> { {} },
604
+ traits: MooseX::Traits::Expires.with(3),
605
+ }
606
+ end
607
+ ```
608
+
609
+ See plugin "ExpiredAttribute" to see how you can specify one expire time and mix with lazy mechanism to auto build in case of not valid value.
593
610
 
594
611
  ##### Create your own trait
595
612
 
@@ -655,7 +672,7 @@ EmailMessage.new.
655
672
 
656
673
  ### Plugin ExpiredAttribute
657
674
 
658
- It is a easy way to apply the trait Expired in lazy attributes!
675
+ It is a easy way to apply the trait Expired in lazy attributes, and auto build the attribute if it is not valid!
659
676
 
660
677
  ```ruby
661
678
  require 'moosex'
@@ -666,7 +683,7 @@ class MyClass
666
683
 
667
684
  has config: {
668
685
  is: :lazy,
669
- clearer: true, # mandatory
686
+ clearer: true, # optional, if not specify, we will force the default clearer method
670
687
  expires: 60, # seconds
671
688
  }
672
689
 
@@ -676,16 +693,17 @@ class MyClass
676
693
  end
677
694
  ```
678
695
 
679
- Instead force a coerce to a tuple, here we use a `expires` keyword. You need enable the clearer to read the configuration, in this case.
696
+ You need enable the clearer to read the configuration, in this case.
680
697
 
681
698
  ### Build your own Plugin
682
699
 
683
- You should create one Class who accepts one parameter in the constructor (it is a reference for the MooseX::Attribute class) and one method 'process' who will be invoked against the argument hash ( in the constructor ). The reference for the attribute can be used to change the original behavoir and you must delete the used arguments from the hash (in process). See the file `lib/moosex/plugins.rb` for more examples.
700
+ You should create one Class who accepts one parameter in the constructor (it is a reference for the MooseX::Attribute class) and one method 'process' who will be invoked against the argument hash ( in the constructor ), and another method prepare. The reference for the attribute can be used to change the original behavoir and you must delete the used arguments from the hash (in process). See the file `lib/moosex/plugins.rb` for more examples.
684
701
 
685
702
  ```ruby
686
703
  module MooseX
687
704
  module Plugins
688
705
  class Chained
706
+ def prepare(options); end
689
707
  def initialize(this)
690
708
  @this = this
691
709
  end
@@ -43,6 +43,16 @@ module MooseX
43
43
  end
44
44
 
45
45
  def init_internal_modifiers(options, plugins, klass)
46
+ plugins.sort.uniq.each do |plugin_klass|
47
+ begin
48
+ plugin_klass.new(self).prepare(options)
49
+ rescue NameError => e
50
+ next
51
+ rescue => e
52
+ raise "Unexpected Error in #{klass} #{plugin_klass} #{@attr_symbol}: #{e}"
53
+ end
54
+ end
55
+
46
56
  @@LIST_OF_PARAMETERS.each do |tuple|
47
57
  parameter, k = tuple
48
58
  @attribute_map[parameter] = k.new(self).process(options, @attr_symbol)
@@ -56,7 +66,7 @@ module MooseX
56
66
  rescue NameError => e
57
67
  next
58
68
  rescue => e
59
- raise "Unexpected Error in #{klass} #{key} #{@attr_symbol}: #{e}"
69
+ raise "Unexpected Error in #{klass} #{plugin_klass} #{@attr_symbol}: #{e}"
60
70
  end
61
71
  end
62
72
 
@@ -1,6 +1,10 @@
1
1
  module MooseX
2
2
  module Plugins
3
3
  class Chained
4
+ def prepare(options)
5
+
6
+ end
7
+
4
8
  def initialize(this)
5
9
  @this = this
6
10
  end
@@ -21,38 +25,37 @@ module MooseX
21
25
  def initialize(this)
22
26
  @this = this
23
27
  end
28
+
29
+ def prepare(options)
30
+ if(options[:expires])
31
+ options[:traits] ||= []
32
+ options[:traits].unshift( MooseX::Traits::Expires.with(options[:expires]) )
33
+
34
+ unless options[:clearer]
35
+ options[:clearer] = true
36
+ end
37
+ end
38
+ end
39
+
24
40
  def process(options)
25
41
  expires = options.delete(:expires) || nil
26
42
 
27
43
  if expires
28
44
  lazy = @this.attribute_map[:lazy]
29
45
  clearer = @this.attribute_map[:clearer]
30
- predicate = @this.attribute_map[:predicate]
31
46
  reader = @this.attribute_map[:reader]
32
- writter = @this.attribute_map[:writter]
33
-
34
- old_traits= @this.attribute_map[:traits]
35
-
36
- @this.attribute_map[:traits] = ->(this) do
37
- MooseX::Traits::Expires.new([ old_traits.call(this), expires ])
38
- end
39
47
 
40
48
  if reader && clearer && lazy
41
- reader_proc = @this.generate_reader
49
+ reader_proc = @this.methods[reader]
42
50
  @this.methods[reader] = ->(this) do
43
- x = reader_proc.call(this)
44
- unless x.valid?
51
+ value = reader_proc.call(this)
52
+ unless value.valid?
45
53
  this.__send__(clearer)
46
- x = reader_proc.call(this)
54
+ value = reader_proc.call(this)
47
55
  end
48
- x
56
+ value
49
57
  end
50
- elsif reader
51
- @this.methods[reader] = @this.generate_reader
52
58
  end
53
- if writter
54
- @this.methods[writter] = @this.generate_writter
55
- end
56
59
  end
57
60
 
58
61
  @this.attribute_map[:expires] = expires
@@ -3,6 +3,17 @@ require 'delegate'
3
3
  module MooseX
4
4
  module Traits
5
5
  class Expires < SimpleDelegator
6
+ def self.with(expires)
7
+ expires2 = Class.new(MooseX::Traits::Expires)
8
+ expires2.class_eval do
9
+ define_method(:initialize) do |value|
10
+ super([ value, expires ])
11
+ end
12
+ end
13
+
14
+ expires2
15
+ end
16
+
6
17
  def initialize(args)
7
18
  value, expires = args[0], args[1]
8
19
  @value = value
@@ -1,3 +1,3 @@
1
1
  module MooseX
2
- VERSION = "0.0.20"
2
+ VERSION = "0.0.21"
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Tiago Peczenyj"]
10
10
  spec.email = ["tiago.peczenyj@gmail.com"]
11
11
  spec.summary = %q{A postmodern object DSL for Ruby}
12
- spec.description = %q{MooseX is an extension of Ruby object DSL. The main goal of MooseX is to make Ruby Object Oriented programming easier, more consistent, and less tedious. With MooseX you can think more about what you want to do and less about the mechanics of OOP. It is a port of Moose/Moo from Perl to Ruby world, providing method delegation, type check, monads, lazy attributes, aspects and much more.}
12
+ spec.description = %q{MooseX is an extension of Ruby object DSL. The main goal of MooseX is to make Ruby Object Oriented programming easier, more consistent, and less tedious. With MooseX you can think more about what you want to do and less about the mechanics of OOP. It is a port of Moose/Moo from Perl to Ruby world, providing method delegation, type check, traits, monads, plugins, lazy attributes, aspects and much more.}
13
13
  spec.homepage = "http://github.com/peczenyj/MooseX"
14
14
  spec.license = "MIT"
15
15
 
@@ -144,8 +144,6 @@ module TestAddAttribute
144
144
 
145
145
  has config: {
146
146
  is: :lazy,
147
- clearer: true,
148
- predicate: true,
149
147
  expires: 4, # seconds
150
148
  }
151
149
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moosex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Peczenyj
@@ -84,7 +84,7 @@ description: MooseX is an extension of Ruby object DSL. The main goal of MooseX
84
84
  to make Ruby Object Oriented programming easier, more consistent, and less tedious.
85
85
  With MooseX you can think more about what you want to do and less about the mechanics
86
86
  of OOP. It is a port of Moose/Moo from Perl to Ruby world, providing method delegation,
87
- type check, monads, lazy attributes, aspects and much more.
87
+ type check, traits, monads, plugins, lazy attributes, aspects and much more.
88
88
  email:
89
89
  - tiago.peczenyj@gmail.com
90
90
  executables: []