yogo-project 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +27 -0
- data/Gemfile +34 -0
- data/Gemfile.lock +198 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/features/step_definitions/yogo_project_steps.rb +0 -0
- data/features/support/env.rb +1 -0
- data/features/yogo_project.feature +9 -0
- data/lib/datamapper/adapters/postgres.rb +9 -0
- data/lib/datamapper/adapters/sqlite.rb +9 -0
- data/lib/yogo-project.rb +2 -0
- data/lib/yogo/collection.rb +12 -0
- data/lib/yogo/collection/asset.rb +12 -0
- data/lib/yogo/collection/asset/model.rb +11 -0
- data/lib/yogo/collection/asset/model_configuration.rb +21 -0
- data/lib/yogo/collection/asset/model_properties.rb +47 -0
- data/lib/yogo/collection/base.rb +69 -0
- data/lib/yogo/collection/base/collection_repository.rb +21 -0
- data/lib/yogo/collection/base/model.rb +20 -0
- data/lib/yogo/collection/base/model_collection_context.rb +25 -0
- data/lib/yogo/collection/base/model_configuration.rb +34 -0
- data/lib/yogo/collection/data.rb +61 -0
- data/lib/yogo/collection/data/model.rb +72 -0
- data/lib/yogo/collection/data/model_configuration.rb +42 -0
- data/lib/yogo/collection/data/model_properties.rb +15 -0
- data/lib/yogo/collection/field_view.rb +26 -0
- data/lib/yogo/collection/form.rb +22 -0
- data/lib/yogo/collection/property.rb +127 -0
- data/lib/yogo/collection/static.rb +13 -0
- data/lib/yogo/collection/static/model_configuration.rb +31 -0
- data/lib/yogo/configuration.rb +9 -0
- data/lib/yogo/datamapper/model/common/properties.rb +16 -0
- data/lib/yogo/datamapper/model/configuration.rb +31 -0
- data/lib/yogo/datamapper/model/operations/add.rb +34 -0
- data/lib/yogo/datamapper/model/operations/clear.rb +29 -0
- data/lib/yogo/datamapper/model/stored/configuration.rb +25 -0
- data/lib/yogo/datamapper/repository_manager.rb +30 -0
- data/lib/yogo/datamapper/repository_manager/model.rb +40 -0
- data/lib/yogo/datamapper/repository_manager/resource.rb +124 -0
- data/lib/yogo/example/dynamic/project_full.rb +48 -0
- data/lib/yogo/example/dynamic/project_remix.rb +16 -0
- data/lib/yogo/example/voeis/managed/data_stream.rb +39 -0
- data/lib/yogo/example/voeis/managed/site.rb +51 -0
- data/lib/yogo/example/voeis/project.rb +57 -0
- data/lib/yogo/operation.rb +49 -0
- data/lib/yogo/project.rb +32 -0
- data/lib/yogo/property_ext.rb +7 -0
- data/spec/resource/.gitdir +0 -0
- data/spec/resource/text_file_asset.txt +1 -0
- data/spec/spec_helper.rb +49 -0
- data/spec/yogo/all_collection_data_models_spec.rb +34 -0
- data/spec/yogo/all_collection_managers_spec.rb +18 -0
- data/spec/yogo/all_collections_spec.rb +54 -0
- data/spec/yogo/all_data_collections_spec.rb +51 -0
- data/spec/yogo/asset_collection_spec.rb +28 -0
- data/spec/yogo/data_collection_spec.rb +16 -0
- data/yogo-project.gemspec +128 -0
- metadata +222 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'yogo/collection/asset/model'
|
2
|
+
require 'yogo/collection/asset/model_properties'
|
3
|
+
|
4
|
+
module Yogo
|
5
|
+
module Collection
|
6
|
+
class Asset < Data
|
7
|
+
module ModelConfiguration
|
8
|
+
def after_model_generate(model)
|
9
|
+
model = super
|
10
|
+
model.extend(Asset::Model)
|
11
|
+
model
|
12
|
+
end
|
13
|
+
|
14
|
+
def after_model_update(model)
|
15
|
+
model.extend(Asset::ModelProperties)
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end # ModelConfiguration
|
19
|
+
end # Data
|
20
|
+
end # Collection
|
21
|
+
end # Yogo
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
require 'yogo/configuration'
|
3
|
+
|
4
|
+
module Yogo
|
5
|
+
module Collection
|
6
|
+
class Asset
|
7
|
+
|
8
|
+
module ModelProperties
|
9
|
+
def self.extended(model)
|
10
|
+
uploader = Class.new(CarrierWave::Uploader::Base)
|
11
|
+
uploader.storage(:file)
|
12
|
+
uploader.class_eval %{
|
13
|
+
def store_dir
|
14
|
+
File.join('#{Configuration.collection.asset.storage_dir}', '#{model.collection.collection_storage_name}')
|
15
|
+
end
|
16
|
+
|
17
|
+
def filename
|
18
|
+
# Digest::MD5.hexdigest(self.read)
|
19
|
+
UUIDTools::UUID.timestamp_create
|
20
|
+
end
|
21
|
+
}, __FILE__, __LINE__+1
|
22
|
+
|
23
|
+
model.class_eval do
|
24
|
+
without_auto_validations do
|
25
|
+
property :content_type, String
|
26
|
+
property :description, String
|
27
|
+
property :asset_file, String
|
28
|
+
property :original_filename, String
|
29
|
+
end
|
30
|
+
|
31
|
+
# validates_uniqueness_of :asset_file
|
32
|
+
|
33
|
+
mount_uploader :file, uploader, :mount_on => :asset_file
|
34
|
+
after :file=, :write_file_identifier
|
35
|
+
after :file=, :set_original_filename
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def set_original_filename
|
40
|
+
attribute_set(:original_filename, file.send(:original_filename))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end # ModelProperties
|
45
|
+
end # Base
|
46
|
+
end # Collection
|
47
|
+
end # Yogo
|
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
require 'yogo/collection/base/collection_repository'
|
3
|
+
require 'yogo/collection/base/model_collection_context'
|
4
|
+
require 'yogo/collection/base/model_configuration'
|
5
|
+
|
6
|
+
module Yogo
|
7
|
+
module Collection
|
8
|
+
module Base
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.extend(Base::CollectionRepository)
|
12
|
+
end
|
13
|
+
|
14
|
+
include Base::CollectionRepository::InstanceMethods
|
15
|
+
include Base::ModelConfiguration
|
16
|
+
|
17
|
+
def collection_storage_name
|
18
|
+
self.id.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def as_json(options={})
|
22
|
+
self.attributes
|
23
|
+
end
|
24
|
+
|
25
|
+
def items(*args)
|
26
|
+
scope do
|
27
|
+
data_model.all(*args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def data_model
|
32
|
+
@_data_model ||= generate_model
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_model(model=data_model)
|
36
|
+
scope do
|
37
|
+
before_model_update(model)
|
38
|
+
model_update(model)
|
39
|
+
if block_given?
|
40
|
+
yield
|
41
|
+
end
|
42
|
+
after_model_update(model)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def scope
|
47
|
+
context = Yogo::Collection.context
|
48
|
+
context << self
|
49
|
+
|
50
|
+
begin
|
51
|
+
yield self
|
52
|
+
ensure
|
53
|
+
context.pop
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def generate_model
|
60
|
+
before_model_generate
|
61
|
+
model = model_generate
|
62
|
+
after_model_generate(model)
|
63
|
+
|
64
|
+
update_model(model)
|
65
|
+
return model
|
66
|
+
end
|
67
|
+
end # Base
|
68
|
+
end # Collection
|
69
|
+
end # Yogo
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Yogo
|
2
|
+
module Collection
|
3
|
+
module Base
|
4
|
+
module CollectionRepository
|
5
|
+
def default_collection_repository_name
|
6
|
+
:collection_data
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
def collection_repository_name
|
11
|
+
self.class.default_collection_repository_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def collection_repository
|
15
|
+
::DataMapper.repository(collection_repository_name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end # CollectionRepository
|
19
|
+
end # Base
|
20
|
+
end # Collection
|
21
|
+
end # Yogo
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Yogo
|
2
|
+
module Collection
|
3
|
+
module Base
|
4
|
+
module Model
|
5
|
+
def to_s
|
6
|
+
"CollectionItemModel[]"
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
def as_json(options=nil)
|
13
|
+
self.attributes
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end # Model
|
18
|
+
end # Base
|
19
|
+
end # Collection
|
20
|
+
end # Yogo
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'yogo/collection'
|
2
|
+
|
3
|
+
module Yogo
|
4
|
+
module Collection
|
5
|
+
module Base
|
6
|
+
module ModelCollectionContext
|
7
|
+
def current_collection
|
8
|
+
Yogo::Collection.context.last
|
9
|
+
end
|
10
|
+
|
11
|
+
def collection
|
12
|
+
current_collection
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_storage_name
|
16
|
+
(current_collection && current_collection.collection_storage_name) || super
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_repository_name
|
20
|
+
(current_collection && current_collection.collection_repository_name) || super
|
21
|
+
end
|
22
|
+
end # ModelCollectionContext
|
23
|
+
end # Static
|
24
|
+
end # Collection
|
25
|
+
end # Yogo
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yogo/collection/base/model'
|
2
|
+
|
3
|
+
module Yogo
|
4
|
+
module Collection
|
5
|
+
module Base
|
6
|
+
module ModelConfiguration
|
7
|
+
def model_generate
|
8
|
+
::DataMapper::Model.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def before_model_generate
|
12
|
+
end
|
13
|
+
|
14
|
+
def after_model_generate(model)
|
15
|
+
model.extend(Base::Model)
|
16
|
+
model.send(:include, Base::Model::InstanceMethods)
|
17
|
+
model.extend(Base::ModelCollectionContext)
|
18
|
+
end
|
19
|
+
|
20
|
+
def model_update(model)
|
21
|
+
model
|
22
|
+
end
|
23
|
+
|
24
|
+
def before_model_update(model)
|
25
|
+
model
|
26
|
+
end
|
27
|
+
|
28
|
+
def after_model_update(model)
|
29
|
+
model
|
30
|
+
end
|
31
|
+
end # ModelConfiguration
|
32
|
+
end # base
|
33
|
+
end # Collection
|
34
|
+
end # Yogo
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
require 'dm-validations'
|
3
|
+
require 'dm-types/uuid'
|
4
|
+
require 'dm-timestamps'
|
5
|
+
|
6
|
+
require 'yogo/configuration'
|
7
|
+
require 'yogo/collection/base'
|
8
|
+
require 'yogo/collection/data/model_configuration'
|
9
|
+
require 'yogo/collection/property'
|
10
|
+
|
11
|
+
module Yogo
|
12
|
+
module Collection
|
13
|
+
class Data
|
14
|
+
include ::DataMapper::Resource
|
15
|
+
|
16
|
+
|
17
|
+
property :id, UUID, :key => true, :default => lambda { |p,r| Yogo::Configuration.random_uuid }
|
18
|
+
property :name, String, :required => true
|
19
|
+
property :description, String
|
20
|
+
property :type, Discriminator
|
21
|
+
|
22
|
+
property :project_id, UUID
|
23
|
+
belongs_to :project, :model => 'Yogo::Project'
|
24
|
+
|
25
|
+
validates_uniqueness_of :name, :scope => :project_id
|
26
|
+
|
27
|
+
has n, :schema, :model => 'Yogo::Collection::Property', :child_key => [:data_collection_id]
|
28
|
+
|
29
|
+
include Collection::Base
|
30
|
+
include Data::ModelConfiguration
|
31
|
+
|
32
|
+
chainable do
|
33
|
+
def as_json
|
34
|
+
{
|
35
|
+
:id => self.id.to_s,
|
36
|
+
:name => self.name,
|
37
|
+
:description => self.description,
|
38
|
+
:type => self.type.to_s,
|
39
|
+
:project => self.project_id.to_s,
|
40
|
+
:schema => self.schema.map{|p| p.id.to_s }
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def update_attributes(hash)
|
45
|
+
attrs = {}
|
46
|
+
attrs[:name] = hash[:name] || hash['name'] || self.name
|
47
|
+
attrs[:description] = hash[:description] || hash['description'] || self.description
|
48
|
+
attrs[:type] = hash[:type] || hash['type'] || self.type || self.class.name
|
49
|
+
self.attributes = attrs
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
|
55
|
+
def resolve_property(options)
|
56
|
+
schema.first(options)
|
57
|
+
end
|
58
|
+
|
59
|
+
end # Base
|
60
|
+
end # Collection
|
61
|
+
end # Yogo
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'dm-timestamps'
|
2
|
+
|
3
|
+
module Yogo
|
4
|
+
module Collection
|
5
|
+
class Data
|
6
|
+
module Model
|
7
|
+
def to_s
|
8
|
+
"DataItemModel[]"
|
9
|
+
end
|
10
|
+
|
11
|
+
def resolve_property(options)
|
12
|
+
collection.send(:resolve_property, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
def self.included(base)
|
18
|
+
base.class_eval do
|
19
|
+
alias_method :[], :named_attribute_get
|
20
|
+
alias_method :[]=, :named_attribute_set
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def as_json(options=nil)
|
25
|
+
hash = super
|
26
|
+
hash[:id] = self.id.to_s
|
27
|
+
hash
|
28
|
+
end
|
29
|
+
|
30
|
+
def named_attribute_get(name)
|
31
|
+
name = name.to_s
|
32
|
+
property = resolve_property(:name => name)
|
33
|
+
property ? attribute_get(property.to_s) : attribute_get(name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def named_attribute_set(name, value)
|
37
|
+
name = name.to_s
|
38
|
+
property = resolve_property(:name => name)
|
39
|
+
property ? attribute_set(property.to_s, value) : attribute_set(name, value)
|
40
|
+
end
|
41
|
+
|
42
|
+
def named_attributes
|
43
|
+
attributes.inject({}) do |h,(k,v)|
|
44
|
+
if k.to_s =~ /^field_/
|
45
|
+
key = k.to_s.gsub(/^field_/,'').gsub('_','-')
|
46
|
+
property = resolve_property(:id => key)
|
47
|
+
h[property.name] = v
|
48
|
+
end
|
49
|
+
h
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def named_attributes=(attrs)
|
54
|
+
attrs = attrs.inject({}) do |h,(k,v)|
|
55
|
+
property = resolve_property(:name => k.to_s)
|
56
|
+
if(property)
|
57
|
+
h[property.to_s.intern] = v
|
58
|
+
end
|
59
|
+
h
|
60
|
+
end
|
61
|
+
self.attributes = attrs
|
62
|
+
end
|
63
|
+
|
64
|
+
def resolve_property(options)
|
65
|
+
self.class.resolve_property(options)
|
66
|
+
end
|
67
|
+
|
68
|
+
end # InstanceMethods
|
69
|
+
end # Model
|
70
|
+
end # Data
|
71
|
+
end # Collection
|
72
|
+
end # Yogo
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'yogo/collection/data/model'
|
2
|
+
require 'yogo/collection/data/model_properties'
|
3
|
+
|
4
|
+
module Yogo
|
5
|
+
module Collection
|
6
|
+
class Data
|
7
|
+
module ModelConfiguration
|
8
|
+
def after_model_generate(model)
|
9
|
+
model = super
|
10
|
+
model.extend(Data::Model)
|
11
|
+
model.send(:include, Data::Model::InstanceMethods)
|
12
|
+
model
|
13
|
+
end
|
14
|
+
|
15
|
+
def before_model_update(model)
|
16
|
+
model = super
|
17
|
+
model.properties.clear
|
18
|
+
model.properties.instance_variable_get(:@properties).clear #clear out the name index
|
19
|
+
# Need to remove relationships too
|
20
|
+
model.relationships.clear
|
21
|
+
model.validators.clear!
|
22
|
+
model
|
23
|
+
end
|
24
|
+
|
25
|
+
def model_update(model)
|
26
|
+
model = super
|
27
|
+
schema.reload
|
28
|
+
schema.each do |field|
|
29
|
+
field.add_to_model(model)
|
30
|
+
end
|
31
|
+
model
|
32
|
+
end
|
33
|
+
|
34
|
+
def after_model_update(model)
|
35
|
+
model.extend(Data::ModelProperties)
|
36
|
+
model.auto_upgrade!
|
37
|
+
model
|
38
|
+
end
|
39
|
+
end # ModelConfiguration
|
40
|
+
end # Data
|
41
|
+
end # Collection
|
42
|
+
end # Yogo
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Yogo
|
2
|
+
module Collection
|
3
|
+
class Data
|
4
|
+
module ModelProperties
|
5
|
+
def self.extended(model)
|
6
|
+
model.class_eval do
|
7
|
+
property :id, UUID, :key => true, :default => lambda { |p,r| UUIDTools::UUID.timestamp_create }
|
8
|
+
property :created_at, DateTime
|
9
|
+
property :updated_at, DateTime
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end # ModelProperties
|
13
|
+
end # Base
|
14
|
+
end # Collection
|
15
|
+
end # Yogo
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
require 'dm-types/uuid'
|
3
|
+
require 'dm-types/yaml'
|
4
|
+
|
5
|
+
require 'yogo/collection/field'
|
6
|
+
require 'yogo/collection/form'
|
7
|
+
|
8
|
+
module Yogo
|
9
|
+
module Collection
|
10
|
+
class FieldView
|
11
|
+
include ::DataMapper::Resource
|
12
|
+
|
13
|
+
property :id, UUID, :key => true, :default => lambda { |p,r| UUIDTools::UUID.timestamp_create }
|
14
|
+
property :label, String,
|
15
|
+
property :type, String, :required => true, :default => 'textfield'
|
16
|
+
property :options, Yaml, :default => {}.to_yaml
|
17
|
+
|
18
|
+
belongs_to :field
|
19
|
+
belongs_to :form
|
20
|
+
|
21
|
+
def label
|
22
|
+
ActiveSupport::Inflector.titleize(attribute_get(:label) || field.field_name || '')
|
23
|
+
end
|
24
|
+
end # FieldView
|
25
|
+
end # Collection
|
26
|
+
end # Yogo
|