morph 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +2 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lib/morph.rb +10 -28
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e0a6b2a59ef3ddad777af1427b8156a15ebde94a8ac5d7f00ab8d53afa1ed7eb
|
4
|
+
data.tar.gz: e7405190734cd1fd61dbd8f6a8af3cc3387e9c587f3a03cbaaab520cd2eb49b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d24c2be5594671ef4402e4b4d08dc9210ce9080444d4f43f111ef3de77b58004a236af71821a210fbddcefda726ff85ef69259f3661b3f2b81df4c383927741
|
7
|
+
data.tar.gz: d8d1aa076c05ad4bc74df0cd210a4c1e2cf622bf04081f277dfa7ede30594964877a5e55ff39a9f2bfbc1b0fb608f6b02c22f51a284fa1fed58dd3778de52aa1
|
data/CHANGELOG
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
data/lib/morph.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
end
|
1
|
+
require 'csv'
|
2
|
+
|
4
3
|
begin
|
5
|
-
# require 'active_support'
|
6
4
|
require 'active_support/core_ext/object/blank'
|
7
5
|
require 'active_support/inflector'
|
8
6
|
require 'active_support/core_ext/string/inflections'
|
@@ -63,11 +61,7 @@ module Chas
|
|
63
61
|
end
|
64
62
|
|
65
63
|
def self.morph_methods klass
|
66
|
-
methods =
|
67
|
-
@morph_methods[klass].keys.sort
|
68
|
-
else
|
69
|
-
@morph_methods[klass].keys.map(&:to_s).sort
|
70
|
-
end
|
64
|
+
methods = @morph_methods[klass].keys.sort
|
71
65
|
|
72
66
|
if klass.superclass.respond_to?(:morph_attributes)
|
73
67
|
methods += klass.superclass.morph_methods
|
@@ -97,9 +91,7 @@ module Chas
|
|
97
91
|
|
98
92
|
def self.morph_method_missing object, symbol, *args
|
99
93
|
attribute = symbol.to_s.chomp '='
|
100
|
-
|
101
|
-
attribute = attribute.to_sym
|
102
|
-
end
|
94
|
+
attribute = attribute.to_sym
|
103
95
|
|
104
96
|
if Object.instance_methods.include?(attribute)
|
105
97
|
raise "'#{attribute}' is an instance_method on Object, cannot create accessor methods for '#{attribute}'"
|
@@ -132,7 +124,7 @@ module Chas
|
|
132
124
|
end
|
133
125
|
|
134
126
|
module Morph
|
135
|
-
VERSION = '0.
|
127
|
+
VERSION = '0.6.0' unless defined? Morph::VERSION
|
136
128
|
|
137
129
|
class << self
|
138
130
|
def classes
|
@@ -157,23 +149,13 @@ module Morph
|
|
157
149
|
|
158
150
|
def from_csv csv, class_name, namespace=Morph
|
159
151
|
objects = []
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
puts "\nYou need to install the fastercsv gem to use Morph.from_csv() with Ruby 1.8"
|
165
|
-
puts " gem install fastercsv\n"
|
152
|
+
CSV.parse(csv, { :headers => true }) do |row|
|
153
|
+
object = object_from_name class_name, namespace
|
154
|
+
row.each do |key, value|
|
155
|
+
object.morph(key, value)
|
166
156
|
end
|
157
|
+
objects << object
|
167
158
|
end
|
168
|
-
|
169
|
-
csv_utility = (RUBY_VERSION >= "1.9") ? CSV : 'FasterCSV'.constantize
|
170
|
-
csv_utility.parse(csv, { :headers => true }) do |row|
|
171
|
-
object = object_from_name class_name, namespace
|
172
|
-
row.each do |key, value|
|
173
|
-
object.morph(key, value)
|
174
|
-
end
|
175
|
-
objects << object
|
176
|
-
end
|
177
159
|
objects
|
178
160
|
end
|
179
161
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob McKinnon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.1.11
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.1.11
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description:
|
42
|
-
email: rob ~@nospam@~
|
42
|
+
email: rob ~@nospam@~ movingflow
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files:
|
@@ -70,8 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
|
74
|
-
rubygems_version: 2.6.4
|
73
|
+
rubygems_version: 3.0.3
|
75
74
|
signing_key:
|
76
75
|
specification_version: 4
|
77
76
|
summary: Morph allows you to emerge Ruby class definitions from data or by calling
|