activefile 0.0.3 → 0.0.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.rdoc +0 -30
- data/Rakefile +1 -9
- data/lib/active_file/adapter.rb +22 -18
- data/lib/active_file/base.rb +2 -3
- data/lib/activefile.rb +15 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGYzNDVhNjU0OTcxYTM0ZTVhY2YzYWYwMmZhYmFmMGIzYjM2MWU4NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWNlN2EzYTFhMWU0YTM5YjE5M2QxYWUyYzQ3NjY0YjYyNTYxMzk4MA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDZjYzM3ZmFiN2FiOTlkYjNlMjVkNWI5OTI4MTBlN2FkZDdhODM1OTdmNzZm
|
10
|
+
YjViYjRmZDI4NGRiM2NmZjY4MzhlZWEwZWMyMjY2NzdlZDUwNDZjOTY5OTNh
|
11
|
+
MDE2MWI4ZTM0YTNjNzY3NWVmNmJjMzAwODdkNjlhY2QyMjIxMGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2E0ZjAyZTQ3MDA2MDY2MDk2YzllMTk4MGE1ZmZjMmNiY2JiMjA5MzdkMGU0
|
14
|
+
YWY1NDYwYWY4YzkyYTRjYTM1OWExMzQ4M2E3MTk4MjQ0MjA1YWRjMzg5NTFj
|
15
|
+
YmM1OTY1ZmFkZjUyMGUzMjAzYzY4MzgzNGY0NWU1MWNhOGI0YzU=
|
data/README.rdoc
CHANGED
@@ -1,35 +1,5 @@
|
|
1
|
-
== Gem under construction. Base functionality already done, but I still need reorganize it. I work with Unit tests now.
|
2
|
-
|
3
|
-
Please, be patient! All work will be done untill May.
|
4
|
-
|
5
1
|
== Welcome to ActiveFile
|
6
2
|
|
7
3
|
ActiveFile is a lightweight file system ORM.
|
8
4
|
|
9
5
|
Build a persistent domain model by mapping file system objects to Ruby classes. It inherits ActiveRecord-similar interface.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
class Shop < ActiveFile::Base
|
14
|
-
parent_to :product
|
15
|
-
end
|
16
|
-
|
17
|
-
class Product < ActiveFile::Base
|
18
|
-
child_of :shop
|
19
|
-
end
|
20
|
-
|
21
|
-
shop = Shop.new(:name => "Apple Store")
|
22
|
-
shop.save!
|
23
|
-
|
24
|
-
Shop.all.size #> 1
|
25
|
-
|
26
|
-
iPad = Product.new(:name => "iPad", :parent => shop, :data => "The iPad is a line of tablet computers designed and marketed by Apple Inc., which runs Apple's iOS operating system.")
|
27
|
-
iPad.save!
|
28
|
-
|
29
|
-
product = Product.where(:name => "iPad")[0]
|
30
|
-
product.data #> "The iPad "...
|
31
|
-
product.shop #> <Shop instance>
|
32
|
-
product.shop.name #> "Apple Store"
|
33
|
-
|
34
|
-
|
35
|
-
# In result, two persistent files were created, accessible via ORM mechanism.
|
data/Rakefile
CHANGED
@@ -1,14 +1,6 @@
|
|
1
|
-
|
2
1
|
desc "Default Task"
|
3
|
-
task default: [ :test ]
|
4
2
|
|
5
|
-
|
6
|
-
#Rake::TestTask.new { |t|
|
7
|
-
## t.libs << "test"
|
8
|
-
# t.pattern = 'test/**/*_test.rb'
|
9
|
-
# t.warning = true
|
10
|
-
# t.verbose = true
|
11
|
-
#}
|
3
|
+
task default: [ :test ]
|
12
4
|
|
13
5
|
task :test do
|
14
6
|
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
|
data/lib/active_file/adapter.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
+
require 'active_support/core_ext/object/blank'
|
2
|
+
|
1
3
|
module ActiveFile
|
2
4
|
# Data Source Storage Adapter
|
3
5
|
module Adapter
|
4
6
|
require 'fileutils'
|
5
7
|
RAISE_TRUE = true
|
6
8
|
RAISE_FALSE = false
|
9
|
+
BASE_FOLDER = 'activefiles'
|
7
10
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def base_folder arg
|
13
|
-
puts "BaseFolder is #{arg}"
|
11
|
+
def type
|
12
|
+
self.class.to_s.split("::")[1].downcase
|
13
|
+
#raise "type to be done #{self.class}"
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
16
|
# touch file to read!
|
18
17
|
def load!
|
19
18
|
self.data
|
@@ -26,7 +25,7 @@ module ActiveFile
|
|
26
25
|
|
27
26
|
def data
|
28
27
|
if @self_data == nil
|
29
|
-
@self_data = File.read(self.get_source_path)
|
28
|
+
@self_data = ::File.read(self.get_source_path)
|
30
29
|
end
|
31
30
|
@self_data || ""
|
32
31
|
end
|
@@ -50,7 +49,8 @@ module ActiveFile
|
|
50
49
|
end
|
51
50
|
# Get source filename
|
52
51
|
def get_filename
|
53
|
-
get_name + get_extension
|
52
|
+
#get_name + get_extension
|
53
|
+
get_name
|
54
54
|
end
|
55
55
|
# Alias for get_source_path
|
56
56
|
def get_filepath
|
@@ -101,7 +101,7 @@ module ActiveFile
|
|
101
101
|
# later..
|
102
102
|
old_file_path = get_source_path
|
103
103
|
new_file_path = get_source_folder + new_file_name + get_extension
|
104
|
-
b_result =
|
104
|
+
b_result = !!::File.rename(old_file_path, new_file_path)
|
105
105
|
raise "Unable to rename source" unless b_result
|
106
106
|
self.name = new_file_name
|
107
107
|
if attach
|
@@ -114,20 +114,20 @@ module ActiveFile
|
|
114
114
|
b_result
|
115
115
|
end
|
116
116
|
def new_record?
|
117
|
-
|
118
|
-
!File.exists?(get_source_path)
|
117
|
+
!::File.exists?(get_source_path)
|
119
118
|
end
|
120
119
|
private
|
121
120
|
def save_method(raise_exception_on_error)
|
122
|
-
File.open(get_source_path, "w") do
|
121
|
+
::File.open(get_source_path, "w") do
|
123
122
|
|file| file.write(data.force_encoding('utf-8'))
|
124
123
|
end
|
124
|
+
true
|
125
125
|
rescue => e
|
126
126
|
return raise_exception_on_error == RAISE_TRUE ? raise(e) : false
|
127
127
|
end
|
128
128
|
def delete_method(raise_exception_on_error)
|
129
129
|
delete_file_name = get_source_path
|
130
|
-
File.delete(delete_file_name)
|
130
|
+
::File.delete(delete_file_name)
|
131
131
|
return true
|
132
132
|
rescue => e
|
133
133
|
return raise_exception_on_error == RAISE_TRUE ? raise(e) : false
|
@@ -168,7 +168,7 @@ module ActiveFile
|
|
168
168
|
end
|
169
169
|
|
170
170
|
target = Adapter.get_source_folder(target_type) + target_name + target_type_extension
|
171
|
-
return nil unless File.exists?(target)
|
171
|
+
return nil unless ::File.exists?(target)
|
172
172
|
return Source.new({ :type => target_type.to_i, :name => target_name, :data => nil })
|
173
173
|
end
|
174
174
|
# Get attached object
|
@@ -195,19 +195,23 @@ module ActiveFile
|
|
195
195
|
#
|
196
196
|
# STATIC METHODS MODULE
|
197
197
|
module ClassMethods
|
198
|
+
def base_folder arg
|
199
|
+
puts "BaseFolder is #{arg}"
|
200
|
+
end
|
198
201
|
# Creates a new source instance and saves it to disk. Returns the newly created source. If a failure has occurred or source already exists -
|
199
202
|
# an exception will be raised.
|
200
203
|
def create(attributes={})
|
201
204
|
raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
|
202
205
|
source_instance = Source.new(attributes)
|
203
|
-
raise 'Source file with such name already exists!' if File.exists?(source_instance.get_source_path)
|
206
|
+
raise 'Source file with such name already exists!' if ::File.exists?(source_instance.get_source_path)
|
204
207
|
source_instance.save!
|
205
208
|
return source_instance
|
206
209
|
end
|
207
210
|
# Get source folder for any source type. Create, if not exists.
|
208
211
|
def get_source_folder(type)
|
209
|
-
source_folder = Rails.env == 'test' ? TEST_SOURCE_FOLDERS[type.to_i || SourceType::UNDEFINED] : SOURCE_FOLDERS[type.to_i || SourceType::UNDEFINED]
|
210
|
-
|
212
|
+
#source_folder = Rails.env == 'test' ? TEST_SOURCE_FOLDERS[type.to_i || SourceType::UNDEFINED] : SOURCE_FOLDERS[type.to_i || SourceType::UNDEFINED]
|
213
|
+
source_folder = "activefiles/" + type.to_s + "/"
|
214
|
+
FileUtils.mkpath(source_folder) unless ::File.exists?(source_folder)
|
211
215
|
return source_folder
|
212
216
|
end
|
213
217
|
# Get names array of all sources with specified type
|
data/lib/active_file/base.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module ActiveFile
|
2
2
|
require 'ostruct'
|
3
3
|
class Base < OpenStruct
|
4
|
-
|
5
|
-
|
6
4
|
include Adapter
|
7
5
|
extend Adapter::ClassMethods
|
8
6
|
def ahola
|
9
|
-
|
7
|
+
return "ahola here!!!!"
|
10
8
|
end
|
9
|
+
|
11
10
|
#'a'.camelize.safe_constantize
|
12
11
|
#def child_of(parent_name)
|
13
12
|
# puts "ok, I am a child of #{parent_name}"
|
data/lib/activefile.rb
CHANGED
@@ -21,9 +21,20 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
|
24
|
+
# For local gem development, we don't want reload server each time,
|
25
|
+
# when gem was changed. Thanks Huiming Teo aka Teohm for his solution,
|
26
|
+
# that was implemented in nice gem 'require_reloader': https://github.com/teohm/require_reloader.
|
27
|
+
# ActiveSupport's Autoload feature not work with it, but this small workaround helps:
|
28
|
+
LOCAL_DEVELOPMENT = true
|
29
|
+
|
25
30
|
module ActiveFile
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
if LOCAL_DEVELOPMENT
|
32
|
+
require 'active_file/adapter'
|
33
|
+
require 'active_file/base'
|
34
|
+
else
|
35
|
+
require "active_support/dependencies/autoload"
|
36
|
+
extend ActiveSupport::Autoload
|
37
|
+
autoload :Base
|
38
|
+
autoload :Adapter
|
39
|
+
end
|
29
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activefile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.31
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitaly Pestov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Build a hierarchical model of filesystem objects.
|
14
14
|
email: vitalyp@softwareplanet.uk.com
|