muesli 0.0.1 → 0.0.2
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/lib/muesli/adapters/cancan.rb +28 -0
- data/lib/muesli/attribute_serializers/base.rb +13 -0
- data/lib/muesli/attribute_serializers/date.rb +11 -0
- data/lib/muesli/attribute_serializers/date_time.rb +11 -0
- data/lib/muesli/attribute_serializers/moped_bson_objectid.rb +13 -0
- data/lib/muesli/attribute_serializers/time.rb +9 -0
- data/lib/muesli/serializers/base.rb +40 -0
- data/lib/muesli.rb +7 -2
- metadata +8 -3
- data/lib/muesli/base_serializer.rb +0 -52
- data/lib/muesli/cancan.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5207efed312b06072f78b5df9076b88d2e939ed
|
4
|
+
data.tar.gz: 2a7d581ca91a43f62830a37d10f1104231d66c9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c38e9e896d58770795d967257f907a6361cd56620cc95a41944151c1e44073e82805f754e2ab4663c1697f403bb4c7dd20a7c7d15419d7bcbbbfc8968c49cb2
|
7
|
+
data.tar.gz: e29e41ca99af7f301ca6abdc3bbdbf66d4f4f699ce5c194ff57e90b62913e2b343bb2da2e50dfb0da50bb38e70da5de4cfd5d5fd2ffb6e110b1cd9bad49d45d4
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Muesli
|
2
|
+
module Adapters
|
3
|
+
module CanCan
|
4
|
+
attr_accessor :ability
|
5
|
+
|
6
|
+
def for_user(user)
|
7
|
+
self.user = user
|
8
|
+
self.ability = Ability.new(user)
|
9
|
+
|
10
|
+
return self
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def can?(*args)
|
16
|
+
return false unless user
|
17
|
+
|
18
|
+
ability.can? *args
|
19
|
+
end
|
20
|
+
|
21
|
+
def cannot?(*args)
|
22
|
+
return true unless user
|
23
|
+
|
24
|
+
ability.cannot *args
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Muesli
|
2
|
+
module Serializers
|
3
|
+
class Base
|
4
|
+
class << self
|
5
|
+
attr_accessor :whitelisted_attributes
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :model, :user
|
9
|
+
|
10
|
+
def initialize(model)
|
11
|
+
self.model = model
|
12
|
+
end
|
13
|
+
|
14
|
+
def serialize
|
15
|
+
return serialize_from_model(self.class.whitelisted_attributes || [])
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def serialize_from_model(attribute_list)
|
21
|
+
serialize_attributes(model, attribute_list)
|
22
|
+
end
|
23
|
+
|
24
|
+
def serialize_attributes(attribute_source, attribute_list)
|
25
|
+
return attribute_list.reduce({}) do |memo, attr|
|
26
|
+
memo[attr] = serialize_value( attribute_source.send(attr) )
|
27
|
+
memo
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def serialize_value(value)
|
32
|
+
if Muesli::AttributeSerializers.const_defined?(value.class.to_s, false)
|
33
|
+
return Muesli::AttributeSerializers.const_get(value.class.to_s, false).new(value).serialize
|
34
|
+
else
|
35
|
+
return Muesli::AttributeSerializers::Base.new(value).serialize
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/muesli.rb
CHANGED
@@ -1,2 +1,7 @@
|
|
1
|
-
require 'muesli/
|
2
|
-
require 'muesli/
|
1
|
+
require 'muesli/attribute_serializers/base'
|
2
|
+
require 'muesli/attribute_serializers/time'
|
3
|
+
require 'muesli/attribute_serializers/date'
|
4
|
+
require 'muesli/attribute_serializers/date_time'
|
5
|
+
require 'muesli/attribute_serializers/moped_bson_objectid'
|
6
|
+
require 'muesli/serializers/base'
|
7
|
+
require 'muesli/adapters/cancan'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muesli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Connor
|
@@ -18,8 +18,13 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/muesli.rb
|
21
|
-
- lib/muesli/
|
22
|
-
- lib/muesli/
|
21
|
+
- lib/muesli/adapters/cancan.rb
|
22
|
+
- lib/muesli/attribute_serializers/base.rb
|
23
|
+
- lib/muesli/attribute_serializers/date.rb
|
24
|
+
- lib/muesli/attribute_serializers/date_time.rb
|
25
|
+
- lib/muesli/attribute_serializers/moped_bson_objectid.rb
|
26
|
+
- lib/muesli/attribute_serializers/time.rb
|
27
|
+
- lib/muesli/serializers/base.rb
|
23
28
|
homepage: https://github.com/onyxrev/muesli
|
24
29
|
licenses:
|
25
30
|
- MIT
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Muesli
|
2
|
-
class BaseSerializer
|
3
|
-
@whitelisted_attributes = []
|
4
|
-
|
5
|
-
class << self
|
6
|
-
attr_accessor :whitelisted_attributes
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_accessor :model, :user
|
10
|
-
|
11
|
-
def initialize(model)
|
12
|
-
self.model = model
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_hash
|
16
|
-
return serialize_attributes(self.class.whitelisted_attributes)
|
17
|
-
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
|
21
|
-
def serialize_attributes(attribute_list)
|
22
|
-
return attribute_list.reduce({}) do |memo, attr|
|
23
|
-
memo[attr] = serialize_value( model.send(attr) )
|
24
|
-
memo
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def serialize_value(value)
|
29
|
-
if [ Date, DateTime, Time ].include? value.class
|
30
|
-
return serialize_date(value)
|
31
|
-
end
|
32
|
-
|
33
|
-
return value
|
34
|
-
end
|
35
|
-
|
36
|
-
def normalize_dates_to_time(date)
|
37
|
-
return date.to_time if date.is_a? Date
|
38
|
-
return date.to_time if date.is_a? DateTime
|
39
|
-
return date if date.is_a? Time
|
40
|
-
|
41
|
-
return nil
|
42
|
-
end
|
43
|
-
|
44
|
-
def serialize_date(date)
|
45
|
-
date = normalize_dates_to_time(date)
|
46
|
-
|
47
|
-
return nil unless date
|
48
|
-
|
49
|
-
return date.iso8601
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/lib/muesli/cancan.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Muesli
|
2
|
-
module CanCan
|
3
|
-
attr_accessor :ability
|
4
|
-
|
5
|
-
def for_user(user)
|
6
|
-
self.user = user
|
7
|
-
self.ability = Ability.new(user)
|
8
|
-
|
9
|
-
return self
|
10
|
-
end
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def can?(*args)
|
15
|
-
return false unless user
|
16
|
-
|
17
|
-
ability.can? *args
|
18
|
-
end
|
19
|
-
|
20
|
-
def cannot?(*args)
|
21
|
-
return true unless user
|
22
|
-
|
23
|
-
ability.cannot *args
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|