define-poro 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 033b78f766bc6090768bb0ab44668594d5f1e6a4
4
- data.tar.gz: a9790b5fbb89d3f539594d5c80b8ee199617bf47
3
+ metadata.gz: a146c56f301e4736fcbebd38b2009c426a0efce8
4
+ data.tar.gz: 3902688e7b28ed1ff378e438ecc83224d744fd2a
5
5
  SHA512:
6
- metadata.gz: 8abf6b17bd0ce8384d46f373dd5af53737a7bec5691e2b4e32b6d0531fc41b18ca2e558d3f6dbfe0b7eae88b4bccffde092fc2f885a133909180b260b6724f66
7
- data.tar.gz: f3774c785ce47070349f4aad8123403b72cf32d292166c9ca45991a382a03da7e0edb41ae07863310497bb8306a05b33e443288561e9295361ef622a64ab5de4
6
+ metadata.gz: 4d4784973eba13d96a8841d079ac0e1bdd121a26ca3d6abeda1e22d65c77fa31a49bf5dc6f248453e4050c19c8c8e7c0c8a0d124449ca9386c6dea88b5c4d556
7
+ data.tar.gz: 2936c60f6ae1b3a4667c407d23c844625ae9f9f794f8f34533ce8685874381c9d164453ad824b9d1f9d6fc7abcc134d52919b5cb9395faa2e1889ab092a8c955
data/README.md CHANGED
@@ -2,7 +2,27 @@
2
2
 
3
3
  Plain Old Ruby Object class builder from provided attribute list and block.
4
4
 
5
- ## Rationale
5
+ ## WARNING
6
+
7
+ Sadly assignment does not handle constants scope well:
8
+
9
+ ```
10
+ RegisterUser = DefinePoro::As.new(:user, :params) do
11
+ USER_TYPE = 1
12
+
13
+ # logic for registering user
14
+ end
15
+
16
+ puts USER_TYPE #> 1 WHAT! constant is bound to outer context
17
+ puts RegisterUser::USER_TYPE #> NameError: uninitialized constant RegisterUser::XX
18
+ ```
19
+
20
+ Conclusion - please use old plain ruby objects with initializer and attr_reader,
21
+ fancy things are not always the best ones.
22
+
23
+ ## History
24
+
25
+ ### Rationale
6
26
 
7
27
  I have been using Struct.new to dynamically create ruby objects that base their identity
8
28
  on functionality and not on values.
@@ -39,21 +59,23 @@ end
39
59
  Ruby guys are lazy so we would like to type something shorter - that's provided by DefinePoro:
40
60
 
41
61
  ```
42
- RegisterUser = DefinePoro::Define.new(:user, :params) do
62
+ RegisterUser = DefinePoro::As.new(:user, :params) do
43
63
  # logic for registering user
44
64
  end
45
65
  ```
46
66
 
47
- The `DefinePoro::Define` implementation is easy and performant ruby code.
67
+ The `DefinePoro::As` implementation is easy and performant ruby code.
48
68
 
49
- ## Should you use it?
69
+ ### Should you use it?
50
70
 
51
71
  Yes - if you are lazy to type initializers.
52
72
 
53
73
  No - if you think that dynamic class definition could be harmful.
54
74
  And I believe that in some cases it could.
55
75
 
56
- ## Installation
76
+ SURELY NOT - sadly assignment does not handle constants scope well.
77
+
78
+ ### Installation
57
79
 
58
80
  Add this line to your application's Gemfile:
59
81
 
@@ -69,7 +91,7 @@ Or install it yourself as:
69
91
 
70
92
  $ gem install define-poro
71
93
 
72
- ## Usage
94
+ ### Usage
73
95
 
74
96
  Instead of
75
97
 
@@ -88,12 +110,12 @@ end
88
110
  Define you class via
89
111
 
90
112
  ```
91
- RegisterUser = DefinePoro::Define.new(:user, :params) do
113
+ RegisterUser = DefinePoro::As.new(:user, :params) do
92
114
  # logic for registering user
93
115
  end
94
116
  ```
95
117
 
96
- ## Contributing
118
+ ### Contributing
97
119
 
98
120
  1. Fork it ( https://github.com/astrauka/define-poro/fork )
99
121
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -101,3 +123,7 @@ end
101
123
  4. Ensure that you have written specs (rspec)
102
124
  5. Push to the branch (`git push origin my-new-feature`)
103
125
  6. Create a new Pull Request
126
+
127
+ ### Changelog
128
+
129
+ `0.1.0` - renamed `DefinePoro::Define` to `DefinePoro::As`
@@ -1,5 +1,5 @@
1
1
  require 'define-poro/version'
2
- require 'define-poro/define'
2
+ require 'define-poro/as'
3
3
 
4
4
  module DefinePoro
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module DefinePoro
2
- class Define
2
+ class As
3
3
  def self.new(*attributes, &block)
4
4
  Class.new do
5
5
  class_eval(%(
@@ -1,3 +1,3 @@
1
1
  module DefinePoro
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module DefinePoro
4
- describe Define do
4
+ describe As do
5
5
  describe '.new' do
6
6
  let(:klass) { described_class.new(:b, :a) }
7
7
 
@@ -25,6 +25,8 @@ module DefinePoro
25
25
 
26
26
  it 'supports block' do
27
27
  klass2 = described_class.new(:a) do
28
+ KLASS2_CONSTANT = 1
29
+
28
30
  def qq
29
31
  "a is #{a}"
30
32
  end
@@ -36,6 +38,8 @@ module DefinePoro
36
38
 
37
39
  expect(klass2.new('1').qq).to eq 'a is 1'
38
40
  expect(klass2.class_qq).to eq 'class qq'
41
+ # !!! constant not bound to klass2 but to outer scope :(
42
+ expect(KLASS2_CONSTANT).to eq 1
39
43
  end
40
44
  end
41
45
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: define-poro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karolis Astrauka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-18 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,10 +81,10 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - lib/define-poro.rb
84
- - lib/define-poro/define.rb
84
+ - lib/define-poro/as.rb
85
85
  - lib/define-poro/version.rb
86
86
  - poro.gemspec
87
- - spec/lib/define_spec.rb
87
+ - spec/lib/as_spec.rb
88
88
  - spec/spec_helper.rb
89
89
  homepage: ''
90
90
  licenses:
@@ -111,5 +111,5 @@ signing_key:
111
111
  specification_version: 4
112
112
  summary: Plain Old Ruby Object class builder from provided attribute list.
113
113
  test_files:
114
- - spec/lib/define_spec.rb
114
+ - spec/lib/as_spec.rb
115
115
  - spec/spec_helper.rb