dyoder-filebase 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -1,10 +1,18 @@
1
1
  module Attributes
2
+
3
+ def initialize(hash = {} )
4
+ attributes = hash
5
+ end
2
6
 
3
- def initialize(hash={})
7
+ def attributes=( hash )
4
8
  # copy the hash, converting all keys to strings
5
9
  @attrs = hash.inject({}) { |h,p| k,v = p; h[k.to_s] = v; h }
6
10
  end
7
11
 
12
+ def attributes
13
+ @attrs ||= {}
14
+ end
15
+
8
16
  def method_missing(name,*args)
9
17
  name = name.to_s
10
18
  if name =~/=$/ and args.length == 1
@@ -23,16 +31,12 @@ module Attributes
23
31
  end
24
32
 
25
33
  def set(name, val)
26
- @attrs[name.to_s] = val
34
+ attributes[name.to_s] = val
27
35
  end
28
36
 
29
37
  def get(name)
30
- rval = ( @attrs[name.to_s] )
31
- if Hash === rval
32
- Dynamo.new(rval)
33
- else
34
- rval
35
- end
38
+ rval = attributes[name.to_s]
39
+ rval.is_a?( Hash ) ? Attributes.new( rval ) : rval
36
40
  end
37
41
 
38
42
  def to_h
@@ -42,5 +46,3 @@ module Attributes
42
46
  alias_method :to_hash, :to_h
43
47
 
44
48
  end
45
-
46
-
@@ -1,5 +1,4 @@
1
- require 'lib/filebase'
2
- require 'lib/attributes'
1
+ require 'filebase/attributes'
3
2
 
4
3
  class Filebase
5
4
 
@@ -27,6 +26,7 @@ class Filebase
27
26
  def create( assigns ) ; save( new( assigns ) ) ; end
28
27
  def all ; db.all.map { |attrs| new( attrs ) } ; end
29
28
  def find( key ) ; attrs = db.find( key ); new( attrs.merge( :key => key ) ) if attrs ; end
29
+ def []( key ) ; find( key ) ; end
30
30
  def save( object )
31
31
  raise( Filebase::Error.new, 'attempted to save an object with nil key' ) if object.key.nil? or object.key.empty?
32
32
  db.save( object.key, object.to_h )
data/lib/filebase.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  require 'rubygems'
2
- require 'lib/yaml'
3
- require 'lib/symbol'
4
- require 'lib/string'
2
+ require 'drivers/yaml'
5
3
  class Filebase
6
4
  class << self ; attr_accessor :storage ; end
7
5
  self.storage = YAML
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyoder-filebase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
- - Dan Yoder, Matthew King, Lawrence Pit
7
+ - Dan Yoder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -30,12 +30,10 @@ extensions: []
30
30
  extra_rdoc_files: []
31
31
 
32
32
  files:
33
- - lib/attributes.rb
33
+ - lib/drivers/yaml.rb
34
+ - lib/filebase/attributes.rb
35
+ - lib/filebase/model.rb
34
36
  - lib/filebase.rb
35
- - lib/model.rb
36
- - lib/string.rb
37
- - lib/symbol.rb
38
- - lib/yaml.rb
39
37
  has_rdoc: true
40
38
  homepage: http://dev.zeraweb.com/waves
41
39
  post_install_message:
@@ -58,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
56
  requirements: []
59
57
 
60
58
  rubyforge_project:
61
- rubygems_version: 1.0.1
59
+ rubygems_version: 1.2.0
62
60
  signing_key:
63
61
  specification_version: 2
64
62
  summary: Simple file-based database with model support.
data/lib/string.rb DELETED
@@ -1,47 +0,0 @@
1
- # Waves extends String with a variety of methods for changing from singular to plural and back, and switching to different types of case and word separators. These methods are similar to those found in Rails and other frameworks, but some (all?) of the names are different. The names here were chosen for increased clarity and are hopefully easy to adjust to ...
2
-
3
- class String
4
-
5
- # Does a File.join on the two arguments joined by the /. Very handy
6
- # for doing platform-safe paths without having to use File.join.
7
- #
8
- # I unfortunately don't recall where i first saw this ... see
9
- # Symbol extension as well, allowing for :files / 'afilename.txt'
10
-
11
- def / ( string )
12
- File.join(self,string.to_s)
13
- end
14
-
15
- def singular
16
- Inflect::English.singular(self)
17
- end
18
-
19
- alias_method(:singularize, :singular)
20
-
21
- def plural
22
- Inflect::English.plural(self)
23
- end
24
-
25
- alias_method(:pluralize, :plural)
26
-
27
- def lower_camel_case
28
- gsub(/(_)(\w)/) { $2.upcase }
29
- end
30
-
31
- def camel_case
32
- lower_camel_case.gsub(/^([a-z])/) { $1.upcase }
33
- end
34
-
35
- def snake_case
36
- gsub(/([a-z\d])([A-Z])/){ "#{$1}_#{$2}"}.tr("-", "_").downcase
37
- end
38
-
39
- def title_case
40
- gsub(/(^|\s)\s*([a-z])/) { $1 + $2.upcase }
41
- end
42
-
43
- def text
44
- gsub(/[\_\-\.\:]/,' ')
45
- end
46
-
47
- end
data/lib/symbol.rb DELETED
@@ -1,7 +0,0 @@
1
- class Symbol
2
- # Does File.join on self and string, converting self to string before invocation.
3
- # See String#/ for more.
4
- def / ( string )
5
- self.to_s / string
6
- end
7
- end