pobject 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +11 -8
- data/lib/pobject/pobject.rb +11 -2
- data/lib/pobject/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 623314560836424e756ded9a17712557f2c8d0c1
|
4
|
+
data.tar.gz: 360cb6821ec9dda6a64b7f7ec3e26063fa321eaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 195d279f3842c41b4e24b9ac03a2ccba68122071d1bf12929b576d9d00590bb968ce4368ecdc939c10e0cd2defbdf567efcf4cc9402bd244ff8efc387860b867
|
7
|
+
data.tar.gz: 100f4672e6c69c6a76bfb44ae9c19da24a26d303035a16407f164270b7dff7a44f77d9980f369b53de8fdedebf00404aec3161c495e633ef2b20d87e3cff713f
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ gem 'pobject'
|
|
28
28
|
Usage
|
29
29
|
--------------------------------------------------
|
30
30
|
|
31
|
-
Your object should inherit from PObject
|
31
|
+
Your object should inherit from `PObject`.
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
require 'pobject'
|
@@ -37,8 +37,8 @@ class Settings < PObject
|
|
37
37
|
end
|
38
38
|
```
|
39
39
|
|
40
|
-
Now, any time you access a property, it is saved to a file. By default, we
|
41
|
-
|
40
|
+
Now, any time you access a property, it is saved to a file. By default, we
|
41
|
+
will save a YAML file with the same name as the class.
|
42
42
|
|
43
43
|
|
44
44
|
```ruby
|
@@ -50,9 +50,9 @@ config.port = 3000
|
|
50
50
|
# Will create a 'settings.yml' file and store the port value
|
51
51
|
```
|
52
52
|
|
53
|
-
You can access any
|
53
|
+
You can access any property by either dot notation or hash notation.
|
54
54
|
|
55
|
-
```
|
55
|
+
```ruby
|
56
56
|
config.port
|
57
57
|
# => 3000
|
58
58
|
|
@@ -74,8 +74,9 @@ config.port = 3000
|
|
74
74
|
# Will create a 'config/local.yml'
|
75
75
|
```
|
76
76
|
|
77
|
-
Whenever you use the `.yml` extension,
|
78
|
-
wish to store a `PStore` object instead,
|
77
|
+
Whenever you use the `.yml` (or `.yaml`) extension, we will store a YAML
|
78
|
+
file. If you wish to store a `PStore` object instead, use any other
|
79
|
+
extension.
|
79
80
|
|
80
81
|
```ruby
|
81
82
|
class Settings < PObject
|
@@ -105,6 +106,8 @@ raynor = Hero.new :raynor
|
|
105
106
|
|
106
107
|
hammer.name = 'Sgt. Hammer'
|
107
108
|
raynor.name = 'Raynor'
|
109
|
+
|
110
|
+
puts File.read 'heroes.yml'
|
108
111
|
# =>
|
109
112
|
# ---
|
110
113
|
# :hammer:
|
@@ -115,7 +118,7 @@ raynor.name = 'Raynor'
|
|
115
118
|
|
116
119
|
By default, PObject will raise an error when accessing a property that does
|
117
120
|
not exist. To change this behavior, call `allow_missing` at the beinning of
|
118
|
-
your
|
121
|
+
your class.
|
119
122
|
|
120
123
|
```ruby
|
121
124
|
class Book < PObject
|
data/lib/pobject/pobject.rb
CHANGED
@@ -48,7 +48,7 @@ class PObject
|
|
48
48
|
# Return a nice string when inspecting or printing.
|
49
49
|
# This will load values from the store if they were not already loaded.
|
50
50
|
def inspect
|
51
|
-
properties = attributes.map { |var| [var, get(var)].join(":") }.join ', '
|
51
|
+
properties = attributes.sort.map { |var| [var, get(var).to_s].join(":") }.join ', '
|
52
52
|
properties = " #{properties}" unless properties.empty?
|
53
53
|
"<#{self.class.name}#{properties}>"
|
54
54
|
end
|
@@ -63,7 +63,16 @@ class PObject
|
|
63
63
|
# Return attribute names from the store.
|
64
64
|
# TODO: Maybe also merge with instance_variables. Pay attention to @s.
|
65
65
|
def attributes!
|
66
|
-
|
66
|
+
result = []
|
67
|
+
store.transaction do
|
68
|
+
if store_key
|
69
|
+
result = store[store_key] || {}
|
70
|
+
result = result.keys
|
71
|
+
else
|
72
|
+
result = store.roots
|
73
|
+
end
|
74
|
+
end
|
75
|
+
result = result.select { |a| a.is_a? Symbol }
|
67
76
|
end
|
68
77
|
|
69
78
|
private
|
data/lib/pobject/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pobject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: runfile
|