openopus-core-people 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +2 -3
- data/app/models/person.rb +9 -4
- data/app/models/user.rb +12 -11
- data/lib/openopus/core/people/engine.rb +0 -1
- data/lib/openopus/core/people/version.rb +1 -1
- data/lib/tasks/openopus/core/people/tasks.rake +44 -0
- metadata +4 -5
- data/lib/openopus/core/people/#engine.rb# +0 -16
- data/lib/tasks/openopus/core/people_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a32e45900d99949c6820082a510cdd0f5ee3204a1fc6f6afc61f780a4ed258f
|
4
|
+
data.tar.gz: 9be748d9522502f97c8974b429d51e298333661f1cb570a6ffeb1d221957e1e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57cbc96b213c460c368b091990c521a668693c8ad5969584ee5ac64d5a724676e44f117f8c079cc598ce466b3c0493490b24a8a4dcf1453813a8573969bf09cc
|
7
|
+
data.tar.gz: a6a59f15c705d43d29635dbaa00b8795d7383b4807a506d07b7ed048f57d613d49f15167daacab5ebf654d94ba4707592e0f6a7899d8971680fdd5dc01bff485
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Install the gem, run migrations. This will create human structures, from Organi
|
|
17
17
|
Add this line to your application's Gemfile:
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
gem 'openopus-core-people', git: "https://github.com/
|
20
|
+
gem 'openopus-core-people', git: "https://github.com/openopus/openopus-core-people"
|
21
21
|
```
|
22
22
|
|
23
23
|
And then execute:
|
data/Rakefile
CHANGED
@@ -15,12 +15,11 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
15
15
|
end
|
16
16
|
|
17
17
|
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
18
|
-
load 'rails/tasks/engine.rake'
|
19
|
-
|
18
|
+
# load 'rails/tasks/engine.rake'
|
20
19
|
load 'rails/tasks/statistics.rake'
|
20
|
+
load 'lib/tasks/openopus/core/people/tasks.rake'
|
21
21
|
|
22
22
|
require 'bundler/gem_tasks'
|
23
|
-
|
24
23
|
require 'rake/testtask'
|
25
24
|
|
26
25
|
Rake::TestTask.new(:test) do |t|
|
data/app/models/person.rb
CHANGED
@@ -122,7 +122,7 @@ class Person < ApplicationRecord
|
|
122
122
|
components = []
|
123
123
|
|
124
124
|
if prefix.present?
|
125
|
-
if not prefix.include?(".")
|
125
|
+
if not prefix.include?(".") and not prefix =~ /^miss$/i
|
126
126
|
components << "#{prefix}."
|
127
127
|
else
|
128
128
|
components << prefix
|
@@ -231,8 +231,8 @@ class Person < ApplicationRecord
|
|
231
231
|
|
232
232
|
def add_address(address_line, label="Home")
|
233
233
|
if self != self.class.find_by_address(address_line)
|
234
|
-
a = Address.parse(address_line)
|
235
|
-
a.addressable_type = self.class.name
|
234
|
+
a = Address.parse(address_line)
|
235
|
+
a.addressable_type = self.class.name
|
236
236
|
a.label = Label.get(label)
|
237
237
|
a.save
|
238
238
|
addresses << a
|
@@ -240,5 +240,10 @@ class Person < ApplicationRecord
|
|
240
240
|
a = Address.find_by_address(address_line)
|
241
241
|
end
|
242
242
|
|
243
|
-
|
243
|
+
def as_api_json(options={})
|
244
|
+
candidate = self.as_json(options)
|
245
|
+
candidate[:emails] = self.emails.collect {|e| { label: e.label, address: e.address }}
|
246
|
+
candidate[:addresses] = self.addresses.collect {|a| { label: a.label, address: a.address }}
|
247
|
+
candidate
|
248
|
+
end
|
244
249
|
end
|
data/app/models/user.rb
CHANGED
@@ -3,17 +3,10 @@ class User < ApplicationRecord
|
|
3
3
|
accepts_nested_attributes_for :person
|
4
4
|
has_and_belongs_to_many :organizations
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
delegate
|
10
|
-
delegate :prefix, :prefix, to: :person
|
11
|
-
delegate :suffix, :suffix, to: :person
|
12
|
-
delegate :emails, :emails=, :email, :email=, to: :person
|
13
|
-
delegate :phones, :phones=, :phone, :phone=, to: :person
|
14
|
-
delegate :addresses, :addresses=, :address, :address=, to: :person
|
15
|
-
delegate :birthdate, :birthdate=, to: :person
|
16
|
-
delegate :age, :age=, to: :person
|
6
|
+
NAME_DELEGATES = [:name,:fname,:lname,:minitial,:prefix,:suffix,:emails,:phones,:addresses,:birthdate,:age] +
|
7
|
+
[:name=,:fname=,:lname=,:minitial=,:prefix=,:suffix=,:emails=,:phones=,:addresses=,:birthdate=,:age=]
|
8
|
+
|
9
|
+
delegate(*NAME_DELEGATES, to: :person)
|
17
10
|
|
18
11
|
def self.lookup(item)
|
19
12
|
person = Person.lookup(item)
|
@@ -27,4 +20,12 @@ class User < ApplicationRecord
|
|
27
20
|
def organization
|
28
21
|
self.organizations.order(created_at: :desc).first
|
29
22
|
end
|
23
|
+
|
24
|
+
def assign_attributes(attr)
|
25
|
+
if not attr.keys.to_set.intersection(NAME_DELEGATES).empty?
|
26
|
+
self.person = Person.new
|
27
|
+
end
|
28
|
+
super(attr)
|
29
|
+
end
|
30
|
+
|
30
31
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
namespace :openopus do
|
2
|
+
namespace :core do
|
3
|
+
namespace :people do
|
4
|
+
desc "Generate one or many random people in your database. Requires 'gem rest-client'. Only for testing!"
|
5
|
+
task :generate_people, [:count] => :environment do |task, args|
|
6
|
+
def generate_person
|
7
|
+
json = ActiveSupport::HashWithIndifferentAccess.new(JSON(RestClient::Request.execute(method: :get, url: 'https://randomuser.me/api?format=json&nat=US').body))
|
8
|
+
jp = json[:results][0]
|
9
|
+
l = jp[:location]
|
10
|
+
a = Address.new
|
11
|
+
a.line1 = l[:street].titleize; a.city = l[:city].titleize; a.state = l[:state].titleize;
|
12
|
+
a.postal = l[:postcode].to_s.upcase; a.country = "US"
|
13
|
+
name = jp[:name]
|
14
|
+
p = Person.create(name: "#{name[:title]} #{name[:first]} #{name[:last]}".titleize,
|
15
|
+
phone: jp[:phone], address: a, email: jp[:email],
|
16
|
+
birthdate: jp[:dob][:date], nationality: jp[:nat])
|
17
|
+
p.picture = jp[:picture][:medium] if p.respond_to?("picture=".to_sym)
|
18
|
+
p.photo = jp[:picture][:medium] if p.respond_to?("photo=".to_sym)
|
19
|
+
p
|
20
|
+
end
|
21
|
+
|
22
|
+
count = args[:count]
|
23
|
+
count ||= 1
|
24
|
+
count.to_i.times do
|
25
|
+
person = generate_person
|
26
|
+
puts("openopus made: #{person.name} of #{person.address.oneline}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Generate users from the people in your database that aren't associated with any user. Only for testing!"
|
31
|
+
task :generate_users, [:count] => :environment do |task, args|
|
32
|
+
def generate_user(person)
|
33
|
+
user = User.create(person_id: person.id, status: "generated") if not person.user and not person.email.blank?
|
34
|
+
if user and user.respond_to?(:credentials) and user.credentials.blank?
|
35
|
+
user.credentials.create(password: "password")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Rake::Task["openopus:core:people:generate_people"].invoke(args[:count]) if not args[:count].blank?
|
40
|
+
Person.all.each { |person| generate_user(person) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openopus-core-people
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian J. Fox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -72,11 +72,10 @@ files:
|
|
72
72
|
- db/migrate/00000000000009_create_join_table_organizations_users.rb
|
73
73
|
- db/seeds.rb
|
74
74
|
- lib/openopus/core/people.rb
|
75
|
-
- lib/openopus/core/people/#engine.rb#
|
76
75
|
- lib/openopus/core/people/engine.rb
|
77
76
|
- lib/openopus/core/people/version.rb
|
78
|
-
- lib/tasks/openopus/core/
|
79
|
-
homepage: https://github.com/
|
77
|
+
- lib/tasks/openopus/core/people/tasks.rake
|
78
|
+
homepage: https://github.com/openopus/openopus-core-people
|
80
79
|
licenses:
|
81
80
|
- MIT
|
82
81
|
metadata:
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Openopus
|
2
|
-
module Core
|
3
|
-
module People
|
4
|
-
class Engine < ::Rails::Engine
|
5
|
-
isolate_namespace People
|
6
|
-
initializer :append_migrations do |app|
|
7
|
-
unless app.root.to_s.match(root.to_s)
|
8
|
-
config.paths["db/migrate"].expanded.each do |expanded_path|
|
9
|
-
app.config.paths["db/migrate"] << expanded_path
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|