kelredd-pathsconfig 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == Description
4
4
 
5
- A ruby gem to help configure dynamic file paths for classes in a easy way.
5
+ A ruby gem to help configure dynamic file paths for classes in a easy way. Paths are handled as arrays of path segments that can be joined to form a usable path string.
6
6
 
7
7
  == Installation
8
8
 
@@ -13,14 +13,89 @@ A ruby gem to help configure dynamic file paths for classes in a easy way.
13
13
  # 1. Require the library
14
14
  require 'pathsconfig'
15
15
 
16
- # 2. Create a paths config file in ./config/paths.yml or ./paths.yml
16
+ # 2. Configure Pathsconfig
17
+ Pathsconfig.config = "#{RAILS_ROOT}/config/paths.yml" # -- or --
18
+ Pathsconfig.config = "./some/custom/file.yml"
17
19
 
18
20
  # 3. Have a class that needs those paths
19
- class Foo
20
-
21
+ class Widget
22
+
23
+ include Pathsconfig::Base
24
+ def self.path_config
25
+ :widget
26
+ end
27
+
21
28
  end
22
29
 
23
30
  # 4. Get sweet methods to generate those paths dynamically!
31
+ @widget.path_array(:a_path) # returns an array of path segments
32
+ @widget.path_string(:a_path) # returns the full path string
33
+
34
+ Because you can choose to deal with paths as arrays of path segments, this gem is handy to use in conjunction with the kelredd-repository gem (http://github.com/kelredd/repository).
35
+
36
+ == Sample Paths Config File and Corresponding Model Definitions
37
+
38
+ # Yaml formatted hash
39
+ :widget:
40
+ :static: # Paths are named for reference
41
+ ['"a"', '"static"', '"path"']
42
+ :dynamic:
43
+ ['"a"', '"dynamic"', '"path"', 'self.id', 'self.name', 'self.type_name'] # Paths can use dynamic model data
44
+ :nested:
45
+ ['self.path_array(:static)', '"that"', '"is"', '"nested"'] # Paths can reference other paths
46
+
47
+ :sprocket:
48
+ :dynamic:
49
+ :old: # Paths can be typed
50
+ ['"an old typed"', '"dynamic"', '"path"', 'self.id', 'self.name', 'self.type_name']
51
+ :new:
52
+ ['"a new typed"', '"dynamic"', '"path"', 'self.id', 'self.name', 'self.type_name']
53
+ :nested:
54
+ ['self.widget.path_array(:dynamic)', '"with"', 'self.path_array(:dynamic)'] # Paths can reference paths from other models if associated
55
+
56
+ Basically, anything between the '' marks is evaluated in the model space. This way you have full access to model data when generating model paths
57
+
58
+ class Widget
59
+
60
+ include Pathsconfig::Base
61
+ def self.path_config
62
+ :widget
63
+ end
64
+ def path_type
65
+ type_name == "Big" ? :old : :new
66
+ end
67
+
68
+ ATTRS = [:id, :type_name, :name]
69
+ ATTRS.each {|a| attr_reader a }
70
+
71
+ def initialize(params={})
72
+ ATTRS.each{|a| instance_variable_set("@#{a.to_s}", params[a]) }
73
+ end
74
+
75
+ end
76
+
77
+ class Sprocket
78
+
79
+ include Pathsconfig::Base
80
+ def self.path_config
81
+ :sprocket
82
+ end
83
+ def path_type
84
+ widget.path_type
85
+ end
86
+
87
+ ATTRS = [:id, :type_name, :name]
88
+ ATTRS.each {|a| attr_reader a }
89
+
90
+ def initialize(params={})
91
+ ATTRS.each{|a| instance_variable_set("@#{a.to_s}", params[a]) }
92
+ end
93
+
94
+ def widget
95
+ @widget ||= Widget.new(:id => 1234, :type_name => 'Small', :name => 'Sarah')
96
+ end
97
+
98
+ end
24
99
 
25
100
  == License
26
101
 
@@ -24,7 +24,7 @@ module Pathsconfig
24
24
  end
25
25
 
26
26
  def self.root=(path)
27
- @@root = path
27
+ @@root = Array(path)
28
28
  end
29
29
 
30
30
  def self.root
@@ -3,7 +3,7 @@ module Pathsconfig
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 0
6
+ TINY = 1
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-pathsconfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-30 00:00:00 -07:00
12
+ date: 2009-07-31 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15