Class: Squared::Config::Viewer
- Inherits:
-
Object
- Object
- Squared::Config::Viewer
- Includes:
- Rake::DSL, Squared::Common::Format, Task
- Defined in:
- lib/squared/config.rb
Class Attribute Summary collapse
-
.styles ⇒ Object
readonly
Returns the value of attribute styles.
Instance Attribute Summary collapse
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Class Method Summary collapse
Instance Method Summary collapse
- #add(type, gem: nil, parse: nil, ext: [], opts: {}, command: nil, file: nil) ⇒ Object
- #also(path, type = nil, name: nil, gem: nil, parse: nil, opts: {}) ⇒ Object
- #build {|_self| ... } ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(main = 'package', project: nil, name: nil) ⇒ Viewer
constructor
A new instance of Viewer.
- #inspect ⇒ Object
- #to_s ⇒ Object
Methods included from Squared::Common::Format
#check_style, #emphasize, #enable_aixterm, #log_message, #log_title, #sub_style
Methods included from Squared::Common
#as_a, #finalize!, #get!, #message, #set!
Constructor Details
#initialize(main = 'package', project: nil, name: nil) ⇒ Viewer
Returns a new instance of Viewer.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/squared/config.rb', line 35 def initialize(main = 'package', project: nil, name: nil) if project @project = get!(:project)[project.to_sym] @required = true end @name = (name || @project&.name)&.to_s unless @name msg, hint = project ? [project, 'not found'] : %w[name missing] warn (:warn, msg, subject: self.class, hint: hint, color: !pipe?) @required = true end @main = main @include = {} end |
Class Attribute Details
.styles ⇒ Object (readonly)
Returns the value of attribute styles.
11 12 13 |
# File 'lib/squared/config.rb', line 11 def styles @styles end |
Instance Attribute Details
#main ⇒ Object (readonly)
Returns the value of attribute main.
33 34 35 |
# File 'lib/squared/config.rb', line 33 def main @main end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
33 34 35 |
# File 'lib/squared/config.rb', line 33 def name @name end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
33 34 35 |
# File 'lib/squared/config.rb', line 33 def project @project end |
Class Method Details
.style(name, *args) ⇒ Object
13 14 15 |
# File 'lib/squared/config.rb', line 13 def style(name, *args) styles[name.to_sym]&.clear&.concat(args) end |
.to_s ⇒ Object
17 18 19 |
# File 'lib/squared/config.rb', line 17 def to_s /[^:]+$/.match(super.to_s)[0] end |
Instance Method Details
#add(type, gem: nil, parse: nil, ext: [], opts: {}, command: nil, file: nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/squared/config.rb', line 76 def add(type, gem: nil, parse: nil, ext: [], opts: {}, command: nil, file: nil) type = type.to_s if parse && enabled? require(gem || type) obj = eval(parse) ext = as_a(ext) namespace name do desc format_desc(ext.first || type, command: command) namespace(command || :view) do task type, [:keys] do |_, args| if file read_keys obj, type, file.to_s, collect_args(args, :keys), *ext else read_keys obj, type, args.keys, args.extras, *ext end end end end end rescue LoadError, NameError self else @include[type] = opts self end |
#also(path, type = nil, name: nil, gem: nil, parse: nil, opts: {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/squared/config.rb', line 102 def also(path, type = nil, name: nil, gem: nil, parse: nil, opts: {}) return self unless (file = base_path(path)).exist? ext = chop_extname(file).downcase name ||= file.basename.to_s.chomp(".#{ext}") type = (type || ext).to_s if !parse case type when 'json' parse = 'JSON' when 'yaml', 'yml' type = 'yaml' parse = 'YAML' end end add(type, gem: gem, parse: parse, ext: ext, opts: opts, command: name, file: file) end |
#build {|_self| ... } ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/squared/config.rb', line 50 def build return unless enabled? namespace name do namespace :view do if @include['json'] && !::Rake::Task.task_defined?("#{name}:view:json") desc format_desc('json') task :json, [:keys] do |_, args| require 'json' read_keys JSON, 'json', args.keys, args.extras end end if @include['yaml'] && !::Rake::Task.task_defined?("#{name}:view:yaml") desc format_desc('yaml', 'yml') task :yaml, [:keys] do |_, args| require 'yaml' read_keys YAML, 'yaml', args.keys, args.extras, 'yml', 'yaml' end end end end yield self if block_given? end |
#enabled? ⇒ Boolean
128 129 130 |
# File 'lib/squared/config.rb', line 128 def enabled? !@required || !!project&.enabled? end |
#inspect ⇒ Object
124 125 126 |
# File 'lib/squared/config.rb', line 124 def inspect "#<#{self.class}: #{name} => #{main} {#{@include.keys.join(', ')}}>" end |
#to_s ⇒ Object
120 121 122 |
# File 'lib/squared/config.rb', line 120 def to_s @include.keys.map { |ext| "#{main}.#{ext}" }.join(',') end |